private IList GetFixtures(Assembly assembly, string ns) { ArrayList fixtures = new ArrayList(); log.Debug("Examining assembly for test fixtures"); IList testTypes = GetCandidateFixtureTypes(assembly, ns); log.Debug("Found {0} classes to examine", testTypes.Count); #if NET_2_0 System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); timer.Start(); #endif foreach (Type testType in testTypes) { if (TestFixtureBuilder.CanBuildFrom(testType)) { fixtures.Add(TestFixtureBuilder.BuildFrom(testType)); } } #if NET_2_0 log.Debug("Found {0} fixtures in {1} seconds", fixtures.Count, timer.Elapsed); #else log.Debug("Found {0} fixtures", fixtures.Count); #endif return(fixtures); }
public void LoadCategories() { Test fixture = TestFixtureBuilder.BuildFrom(typeof(HasCategories)); Assert.IsNotNull(fixture); Assert.AreEqual(2, fixture.Categories.Count); }
private TestResult RunTestOnFixture(object fixture) { Test suite = TestFixtureBuilder.BuildFrom(fixture); Assert.AreEqual(1, suite.Tests.Count, "Test case count"); return(suite.Run(NullListener.NULL, TestFilter.Empty)); }
public void SetUp() { testSuite = new TestSuite("MyTestSuite"); testFixture = TestFixtureBuilder.BuildFrom(typeof(MockTestFixture)); testSuite.Add(testFixture); testCase = TestFinder.Find("MockTest1", testFixture, false); }
private TestResult RunTestOnFixture(object fixture) { Test suite = TestFixtureBuilder.BuildFrom(fixture); Assert.AreEqual(1, suite.Tests.Count, "Test case count"); Assert.AreEqual("NUnit.Core.Extensions.RepeatedTestCase", suite.Tests[0].GetType().FullName); return(suite.Run(NullListener.NULL)); }
public void GoodSignature() { string methodName = "TestVoid"; Test fixture = TestFixtureBuilder.BuildFrom(typeof(SignatureTestFixture)); Test foundTest = TestFinder.Find(methodName, fixture); Assert.IsNotNull(foundTest); Assert.AreEqual(RunState.Runnable, foundTest.RunState); }
public void MaxTimeExceeded() { Test test = TestFixtureBuilder.BuildFrom(typeof(MaxTimeFixture)); TestResult result = test.Run(NullListener.NULL, TestFilter.Empty); Assert.AreEqual(ResultState.Failure, result.ResultState); result = (TestResult)result.Results[0]; StringAssert.IsMatch(@"Elapsed time of \d*ms exceeds maximum of 1ms", result.Message); }
public void CategoryWorksWithRepeatedTest() { Test suite = TestFixtureBuilder.BuildFrom(typeof(RepeatedTestWithCategory)); Test test = suite.Tests[0] as Test; Assert.IsNotNull(test.Categories); Assert.AreEqual(1, test.Categories.Count); Assert.AreEqual("SAMPLE", test.Categories[0]); }
public void ErrorReportHasPriorityOverMaxTime() { Test test = TestFixtureBuilder.BuildFrom(typeof(MaxTimeFixtureWithError)); TestResult result = test.Run(NullListener.NULL, TestFilter.Empty); Assert.AreEqual(ResultState.Failure, result.ResultState); result = (TestResult)result.Results[0]; Assert.AreEqual(ResultState.Error, result.ResultState); StringAssert.IsMatch("Exception message", result.Message); }
private Test BuildSingleFixture(Type testType) { // The only place we currently allow legacy suites if (legacySuiteBuilder.CanBuildFrom(testType)) { return(legacySuiteBuilder.BuildFrom(testType)); } return(TestFixtureBuilder.BuildFrom(testType)); }
/// <summary> /// Build a TestSuite from type provided. /// </summary> /// <param name="type">The type of the fixture to be used</param> /// <returns>A TestSuite</returns> public Test BuildFrom(Type type) { TestSuite suite = new LegacySuite(type); if (suite.RunState == RunState.NotRunnable) { string reason = null; if (!IsValidFixtureType(type, ref reason)) { suite.RunState = RunState.NotRunnable; suite.Properties.Set(PropertyNames.SkipReason, reason); } } PropertyInfo suiteProperty = GetSuiteProperty(type); MethodInfo method = suiteProperty.GetGetMethod(true); if (method.GetParameters().Length > 0) { suite.RunState = RunState.NotRunnable; suite.Properties.Set(PropertyNames.SkipReason, "Suite property may not be indexed"); } // TODO: Stop checking for name else if (method.ReturnType.FullName == "NUnit.Framework.Internal.TestSuite") { TestSuite s = (TestSuite)suiteProperty.GetValue(null, new Object[0]); foreach (Test test in s.Tests) { suite.Add(test); } } else if (typeof(IEnumerable).IsAssignableFrom(method.ReturnType)) { foreach (object obj in (IEnumerable)suiteProperty.GetValue(null, new object[0])) { Type objType = obj as Type; if (objType != null && TestFixtureBuilder.CanBuildFrom(objType)) { suite.Add(TestFixtureBuilder.BuildFrom(objType)); } else { suite.Add(TestFixtureBuilder.BuildFrom(obj)); } } } else { suite.RunState = RunState.NotRunnable; suite.Properties.Set(PropertyNames.SkipReason, "Suite property must return either TestSuite or IEnumerable"); } return(suite); }
public void SetUp() { testSuite = new TestSuite("MyTestSuite"); testFixture = TestFixtureBuilder.BuildFrom(typeof(MockTestFixture)); testSuite.Add(testFixture); suiteInfo = new TestInfo(testSuite); fixtureInfo = new TestInfo(testFixture); testCase = (NUnit.Core.Test)testFixture.Tests[0]; testCaseInfo = new TestInfo(testCase); }
public void RepeatedTestIsBuiltCorrectly() { Test suite = TestFixtureBuilder.BuildFrom(typeof(RepeatSuccessFixture)); Assert.IsNotNull(suite, "Unable to build suite"); Assert.AreEqual(1, suite.Tests.Count); Assert.AreEqual("RepeatedTestCase", suite.Tests[0].GetType().Name); TestCase repeatedTestCase = suite.Tests[0] as TestCase; Assert.IsNotNull(repeatedTestCase, "Test case is not a RepeatedTestCase"); Assert.AreSame(suite, repeatedTestCase.Parent); // Assert.AreEqual( "NUnit.TestData.RepeatedTestFixture.RepeatSuccessFixture", repeatedTestCase.FixtureType.FullName ); }
private Test Build(string assemblyName, Type testType, bool autoSuites) { // TODO: This is the only situation in which we currently // recognize and load legacy suites. We need to determine // whether to allow them in more places. if (legacySuiteBuilder.CanBuildFrom(testType)) { return(legacySuiteBuilder.BuildFrom(testType)); } else if (TestFixtureBuilder.CanBuildFrom(testType)) { return(BuildTestAssembly(assemblyName, new Test[] { TestFixtureBuilder.BuildFrom(testType) }, autoSuites)); } return(null); }
private IList GetFixtures(Assembly assembly, string ns) { ArrayList fixtures = new ArrayList(); IList testTypes = GetCandidateFixtureTypes(assembly, ns); foreach (Type testType in testTypes) { if (TestFixtureBuilder.CanBuildFrom(testType)) { fixtures.Add(TestFixtureBuilder.BuildFrom(testType)); } } return(fixtures); }
public TestReport Run(string specificTestName = null, bool skipLocal = false) { var testSuiteTypes = GetTestSuiteTypesUsingReflection(skipLocal); if (testSuiteTypes == null || testSuiteTypes.Length == 0) { return(new TestReport() { Tests = new List <TestReportItem>() }); } var testPackage = new TestPackage("HelthMonitor test package"); var testSuite = new TestSuite("HelthMonitor test suite"); TestExecutionContext.CurrentContext.TestPackage = testPackage; if (string.IsNullOrEmpty(specificTestName)) { foreach (var testSuiteType in testSuiteTypes) { var test = TestFixtureBuilder.BuildFrom(testSuiteType); testSuite.Tests.Add(test); } } else { Test specificTest = null; string specificTestMethod = null; if (specificTestName.Contains("#")) { var tokens = specificTestName.Split('#'); specificTestName = tokens[0]; specificTestMethod = tokens[1]; } var specificTestType = testSuiteTypes.FirstOrDefault(x => x.FullName == specificTestName); if (specificTestType != null) { specificTest = TestFixtureBuilder.BuildFrom(specificTestType); } if (specificTest != null && !string.IsNullOrEmpty(specificTestMethod)) { var testsToRemove = new List <Test>(); foreach (Test test in specificTest.Tests) { var testMethod = test as TestMethod; if (testMethod != null) { if (testMethod.Method.Name != specificTestMethod) { testsToRemove.Add(test); } } } foreach (var test in testsToRemove) { specificTest.Tests.Remove(test); } } if (specificTest != null) { testSuite.Tests.Add(specificTest); } } using (var listener = new NUnitTraceListener(_appInsightsInstrumentationKey)) { var testResult = testSuite.Run(listener, new NUnitTestRunnerFilter()); var testReport = GenerateTestReport(testResult); return(testReport); } }
public void CreateResult() { Test testFixture = TestFixtureBuilder.BuildFrom(typeof(MockTestFixture)); result = testFixture.Run(NullListener.NULL, TestFilter.Empty); }
public TestResult RunAllUnitTests(Action <string> callback, Assembly testAssembly = null) { if (testAssembly == null) { testAssembly = Assembly.GetCallingAssembly(); } CoreExtensions.Host.InitializeService(); TestExecutionContext.CurrentContext.TestPackage = new TestPackage(string.Format("TestPackage for {0}", testAssembly.GetName().FullName)); var builder = new NamespaceTreeBuilder(new TestAssembly(testAssembly, testAssembly.GetName().FullName)); var fixtures = testAssembly.GetTypes().Where(i => TestFixtureBuilder.CanBuildFrom(i)).Select(i => TestFixtureBuilder.BuildFrom(i)).ToList(); builder.Add(fixtures); return(builder.RootSuite.Run(new ConsoleListener(callback), TestFilter.Empty)); }