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

Coverage.GetSequencePointsFor

建议修改

成功!

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

关闭

提交失败

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

关闭

取消

声明

public static CoveredSequencePoint[] GetSequencePointsFor(MethodBase method);

参数

method 要获取序列点的函数。

返回值

CoveredSequencePoint[] 序列点数组。

描述

返回您指定的函数的覆盖率序列点。有关此函数返回的覆盖率数据,请参阅 CoveredSequencePoint

using UnityEngine;
using UnityEngine.TestTools;
using System.Reflection;

public class CoverageClass { // A simple test method to get coverage information from. // If the method is called with incrementValue set to true, // the method will have complete coverage. If incrementValue // is false, the coverage will be incomplete. public int CoveredMethod(bool incrementValue) { int value = 0; if (incrementValue) { value++; }

return value; } }

public class CoverageExample : MonoBehaviour { void Start() { // Create an instance of the test class and call the test method // to make sure the method has had some coverage. Note in this example, // we're passing false into the method to make sure the coverage // is incomplete. CoverageClass coverageClasss = new CoverageClass(); int value = coverageClasss.CoveredMethod(false);

// Use reflection to get the MethodBase for CoverageClass.CoveredMethod MethodBase coveredMethodBase = typeof(CoverageClass).GetMethod("CoveredMethod"); // And get the sequence points for the method. CoveredSequencePoint[] sequencePoints = Coverage.GetSequencePointsFor(coveredMethodBase);

for (int i = 0; i < sequencePoints.Length; i++) { Debug.Log("File: " + sequencePoints[i].filename); Debug.Log("Method Name: " + sequencePoints[i].method.ToString()); Debug.Log("Line: " + sequencePoints[i].line + " Column: " + sequencePoints[i].column); Debug.Log(" IL Offset: " + sequencePoints[i].ilOffset + " Hit Count: " + sequencePoints[i].hitCount); } } }