protected TestFixture LoadTestScripts(ScriptSuiteDefinition definition) { var engine = new Engine(definition.LanguageSetup, definition.EnableDebugging); engine.Initialise(definition.ScriptContext); var tests = new List<Test>(); IList<string> scripts = definition.FindScripts(); var testFixture = new TestFixture(definition.GetType()); foreach (var script in scripts) { var test = new ScriptTest(script, engine); test.Fixture = testFixture; testFixture.Add(test); } return testFixture; }
/// <summary> /// Go through the Test tree, building a tree of TestFixures with Test nodes. /// </summary> private void MapTestTreeToFixtures(TreeDictionary<string, TestClosure> source, TestSuite container, Type fixtureType) { foreach (var testClosure in source.Items) { container.Add(new ClosureTest(testClosure)); } foreach (var child in source.Children) { var fixture = new TestFixture(fixtureType); fixture.TestName.Name = child.Key; foreach (var testClosure in child.Value.Items) { fixture.Add(new ClosureTest(testClosure)); } foreach (var sub_child in child.Value.Children) { var sub_fixture = new TestFixture(fixtureType); sub_fixture.TestName.Name = sub_child.Key; MapTestTreeToFixtures(sub_child.Value, sub_fixture, fixtureType); fixture.Add(sub_fixture); } container.Add(fixture); } }
/// <summary> /// Helper routine that makes a suite from either a TestFixture or /// a legacy Suite property. /// </summary> /// <param name="testType"></param> /// <returns></returns> private TestSuite MakeSuite( Type testType ) { TestSuite suite = null; if(testType != null) { if( TestFixture.IsValidType( testType ) ) { suite = new TestFixture( testType ); } else if( LegacySuite.IsValidType( testType ) ) { suite = new LegacySuite( testType ); } } return suite; }
/// <summary> /// Find an NUnit test method within a given fixture by name. /// </summary> /// <param name="fixture"></param> /// <param name="name"></param> /// <returns></returns> private static Test FindTestByName(TestFixture fixture, string name) { return (from t in fixture.Tests.OfType<Test>() where t.TestName.Name == name select t).FirstOrDefault(); }
/// <summary> /// Find an NUnit test fixture by name. /// </summary> /// <param name="fixture"></param> /// <param name="suite"></param> /// <param name="name"></param> private static void FindFixtureByName(out TestFixture fixture, TestSuite suite, string name) { foreach (TestSuite innerSuite in suite.Tests) { if (innerSuite is TestFixture) { if (((TestFixture)innerSuite).TestName.Name == name) { fixture = innerSuite as TestFixture; return; } } else { FindFixtureByName(out fixture, innerSuite, name); if (fixture != null) return; } } fixture = null; }
/// <summary> /// Run all tests in a fixture. /// </summary> /// <param name="fixture">Returns a list of results. These results are usually testcaseType objects.</param> /// <returns></returns> private IEnumerable<object> RunFixture(TestFixture fixture) { var results = new List<object>(); foreach (var t in fixture.Tests) { if (t is ParameterizedMethodSuite) { var paramSuite = t as ParameterizedMethodSuite; foreach (var tInner in paramSuite.Tests) { if (tInner is TestMethod) { results.Add(RunTest((TestMethod)tInner)); } } } else if (t is TestMethod) { results.Add(RunTest((TestMethod)t)); } } return results; }