版本:Unity 6 (6000.0)
语言English
  • C#

Coverage.GetStatsForAllCoveredMethods

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法采纳所有提交的内容,但我们确实会阅读用户提出的每项更改建议,并在适用情况下进行更新。

关闭

提交失败

由于某些原因,您的更改建议无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

声明

public static CoveredMethodStats[] GetStatsForAllCoveredMethods();

返回值

CoveredMethodStats[] 代码覆盖率摘要数组。

描述

返回自 Unity 进程启动或调用 Coverage.ResetAll() 以来所有已调用的方法的代码覆盖率摘要。

using UnityEngine;
using UnityEngine.TestTools;

// A simple test class to get coverage information for. public class CoverageClass { public bool CoveredMethod1() { return true; }

public bool CoveredMethod2() { return false; } }

public class CoverageExample : MonoBehaviour { void Start() { // Reset coverage Coverage.ResetAll();

// Create an instance of the test class and call both test methods // to make sure the class has had some coverage. CoverageClass coverageClasss = new CoverageClass(); coverageClasss.CoveredMethod1(); coverageClasss.CoveredMethod2();

// Now get coverage statistics for all covered methods. Note that this // will return statistics for all methods that have executed since Coverage.ResetAll() // was last called, i.e. this method (CoverageExample.Start()), CoverageClass.CoveredMethod1(), // and CoverageClass.CoveredMethod2(). CoveredMethodStats[] stats = Coverage.GetStatsForAllCoveredMethods();

for (int i = 0; i < stats.Length; i++) { Debug.Log("Method Name: " + stats[i].method.ToString()); Debug.Log("Method has " + stats[i].totalSequencePoints + " sequence points"); int coveredSequencePoints = stats[i].totalSequencePoints - stats[i].uncoveredSequencePoints; Debug.Log("of which " + coveredSequencePoints + " were covered."); } } }