< Summary

Class:TestBase
Assembly:bamlab.test
File(s):/github/workspace/Assets/Tests/TestBase.cs
Covered lines:0
Uncovered lines:30
Coverable lines:30
Total lines:44
Line coverage:0% (0 of 30)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:6
Method coverage:0% (0 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetPrivateField[T](...)0%2100%
GetPrivateField[T](...)0%2100%
InvokePrivateMethod[T](...)0%2100%
InvokePrivateMethod(...)0%2100%
GetFieldInfo(...)0%6200%
GetMethodInfo(...)0%6200%

File(s)

/github/workspace/Assets/Tests/TestBase.cs

#LineLine coverage
 1using System;
 2using System.Reflection;
 3using NUnit.Framework;
 4using UnityEngine;
 5
 6public abstract class TestBase {
 07  protected void SetPrivateField<T>(object obj, string fieldName, T value) {
 08    FieldInfo field = GetFieldInfo(obj, fieldName);
 09    field.SetValue(obj, value);
 010  }
 11
 012  protected T GetPrivateField<T>(object obj, string fieldName) {
 013    FieldInfo field = GetFieldInfo(obj, fieldName);
 014    return (T)field.GetValue(obj);
 015  }
 16
 017  protected T InvokePrivateMethod<T>(object obj, string methodName, params object[] parameters) {
 018    MethodInfo method = GetMethodInfo(obj, methodName);
 019    return (T)method.Invoke(obj, parameters);
 020  }
 21
 022  protected void InvokePrivateMethod(object obj, string methodName, params object[] parameters) {
 023    MethodInfo method = GetMethodInfo(obj, methodName);
 024    method.Invoke(obj, parameters);
 025  }
 26
 027  private FieldInfo GetFieldInfo(object obj, string fieldName) {
 028    var type = obj.GetType();
 029    var field = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
 030    if (field == null) {
 031      throw new Exception($"Field '{fieldName}' not found in type '{type.FullName}'.");
 32    }
 033    return field;
 034  }
 35
 036  private MethodInfo GetMethodInfo(object obj, string methodName) {
 037    var type = obj.GetType();
 038    var method = type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
 039    if (method == null) {
 040      throw new Exception($"Method '{methodName}' not found in type '{type.FullName}'.");
 41    }
 042    return method;
 043  }
 44}