/// <summary> /// Discovers the tests in the Assembly. /// </summary> /// <param name="dllPath">The path to the DLL.</param> /// <param name="assembly">The loaded Assembly.</param> /// <returns>Tests in the Assembly</returns> protected override List<TestClass> DiscoverTestsInAssembly(string dll, AssemblyDefinition assembly) { var classes2 = new List<TestClass>(); foreach (var type in assembly.MainModule.Types) { bool isMSTest = false; try { var customAttributes = type.CustomAttributes; if (customAttributes != null) { isMSTest = customAttributes.Any(attribute => attribute.AttributeType.FullName == typeof(TestClassAttribute).FullName); } } catch { } if (isMSTest) { var TestClass = new TestClass { DLLPath = dll, Name = type.Name, Namespace = type.Namespace, TestType = TestType.MSTest }; TestClass.TestMethods = DiscoverTestsInClass(type, TestClass); classes2.Add(TestClass); } } return classes2; }
/// <summary> /// Discovers the tests in class. /// </summary> /// <param name="type">Type of the class.</param> /// <returns>Tests in the class</returns> private TestMethod[] DiscoverTestsInClass(TypeDefinition type, TestClass @class) { var tests = new List<TestMethod>(); foreach (var method in type.Methods) { bool isTestMethod = false; var trait = new List<string>(); try { foreach (var attribute in method.CustomAttributes) { if (attribute.AttributeType.FullName == typeof(TestMethodAttribute).FullName) { isTestMethod = true; } AddTraits(trait, attribute, typeof(TestCategoryAttribute)); } } catch { } if (isTestMethod) { TestMethod testMethod = new TestMethod(); testMethod.Name = method.Name; testMethod.Traits = trait.Count > 0 ? trait.ToArray() : new[] { "No Traits" }; tests.Add(testMethod); } } return tests.ToArray(); }
protected override List<TestClass> DiscoverTestsInAssembly(string dllPath, AssemblyDefinition assembly) { var result = new List<TestClass>(); var testCases = GetNunitTestCasesFromDll(dllPath); foreach (var type in assembly.MainModule.Types) { var testCasesInClass = testCases.Where(p => p.StartsWith(type.FullName)); if (testCasesInClass.Count() > 0) { var testClassToAdd = new TestClass() { TestType = TestType.NUnit, DLLPath = dllPath, Name = type.Name, Namespace = type.Namespace, }; var testMethodsToAdd = new List<TestMethod>(); foreach (string testCase in testCasesInClass) testMethodsToAdd.Add(new TestMethod() { Name = testCase.Substring(type.FullName.Length + 1), Traits = new[] { "No Traits" } }); testClassToAdd.TestMethods = testMethodsToAdd.ToArray(); result.Add(testClassToAdd); } } return result; }