/// <summary> /// Builds a ParameterizedMetodSuite containing individual /// test cases for each set of parameters provided for /// this method. /// </summary> /// <param name="method">The MethodInfo for which a test is to be built</param> /// <param name="parentSuite">The test suite for which the method is being built</param> /// <returns>A ParameterizedMethodSuite populated with test cases</returns> public Test BuildParameterizedMethodSuite(MethodInfo method, Test parentSuite) { ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method); #if PORTABLE methodSuite.ApplyAttributesToTest(method.AsCustomAttributeProvider()); #else methodSuite.ApplyAttributesToTest(method); #endif foreach (ITestCaseData testcase in testCaseProvider.GetTestCasesFor(method)) { ParameterSet parms = testcase as ParameterSet; if (parms == null) { parms = new ParameterSet(testcase); } TestMethod test = BuildSingleTestMethod(method, parentSuite, parms); methodSuite.Add(test); } return(methodSuite); }
private Test BuildParameterizedMethodSuite(IMethodInfo method, IEnumerable<TestMethod> tests) { ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method); methodSuite.ApplyAttributesToTest(method.MethodInfo); foreach (TestMethod test in tests) methodSuite.Add(test); return methodSuite; }
public void TestTimeOutTestCaseWithOutElapsed() { TimeoutTestCaseFixture fixture = new TimeoutTestCaseFixture(); TestSuite suite = TestBuilder.MakeFixture(fixture); ParameterizedMethodSuite methodSuite = (ParameterizedMethodSuite)TestFinder.Find("TestTimeOutTestCase", suite, false); ITestResult result = TestBuilder.RunTest(methodSuite, fixture); Assert.That(result.ResultState, Is.EqualTo(ResultState.Failure), "Suite result"); Assert.That(result.Children.ToArray()[0].ResultState, Is.EqualTo(ResultState.Success), "First test"); Assert.That(result.Children.ToArray()[1].ResultState, Is.EqualTo(ResultState.Failure), "Second test"); }
/// <summary> /// Builds a ParameterizedMetodSuite containing individual /// test cases for each set of parameters provided for /// this method. /// </summary> /// <param name="method">The MethodInfo for which a test is to be built</param> /// <returns>A ParameterizedMethodSuite populated with test cases</returns> public static Test BuildParameterizedMethodSuite(MethodInfo method, Test parentSuite) { ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method); NUnitFramework.ApplyCommonAttributes(method, methodSuite); foreach (object source in CoreExtensions.Host.TestCaseProviders.GetTestCasesFor(method, parentSuite)) { ParameterSet parms; if (source == null) { parms = new ParameterSet(); parms.Arguments = new object[] { null }; } else parms = source as ParameterSet; if (parms == null) { if (source.GetType().GetInterface("NUnit.Framework.ITestCaseData") != null) parms = ParameterSet.FromDataSource(source); else { parms = new ParameterSet(); ParameterInfo[] parameters = method.GetParameters(); Type sourceType = source.GetType(); if (parameters.Length == 1 && parameters[0].ParameterType.IsAssignableFrom(sourceType)) parms.Arguments = new object[] { source }; else if (source is object[]) parms.Arguments = (object[])source; else if (source is Array) { Array array = (Array)source; if (array.Rank == 1) { parms.Arguments = new object[array.Length]; for (int i = 0; i < array.Length; i++) parms.Arguments[i] = (object)array.GetValue(i); } } else parms.Arguments = new object[] { source }; } } TestMethod test = BuildSingleTestMethod(method, parentSuite, parms); methodSuite.Add(test); } return methodSuite; }
public void TestTimeOutTestCaseWithOutElapsed() { TimeoutTestCaseFixture fixture = new TimeoutTestCaseFixture(); TestSuite suite = TestBuilder.MakeFixture(fixture); ParameterizedMethodSuite testMethod = (ParameterizedMethodSuite)TestFinder.Find("TestTimeOutTestCase", suite, false); ITestResult result = TestBuilder.RunTest(testMethod, fixture); Assert.That(result.ResultState, Is.EqualTo(ResultState.Cancelled)); Assert.That(result.Children[0].ResultState, Is.EqualTo(ResultState.Success)); Assert.That(result.Children[1].ResultState, Is.EqualTo(ResultState.Failure)); }
/// <summary> /// Decorates a parameterized test suite. /// </summary> /// <param name="paramTests">Test suite.</param> private static void Decorate(ParameterizedMethodSuite paramTests) { for (int i = 0; i < paramTests.Tests.Count; i++) { var test = paramTests.Tests[i]; var nunitTest = test as NUnitTestMethod; if (nunitTest != null) { paramTests.Tests[i] = new InconclusiveTestCase(nunitTest); } } }
/// <summary> /// Builds a ParameterizedMethodSuite containing individual test cases. /// </summary> /// <param name="method">The method to be used as a test.</param> /// <param name="tests">The list of test cases to include.</param> private Test BuildParameterizedMethodSuite(FixtureMethod method, IEnumerable <TestMethod> tests) { ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method); methodSuite.ApplyAttributesToTest(method.Method); foreach (TestMethod test in tests) { methodSuite.Add(test); } return(methodSuite); }
/// <summary> /// Build a Test from the provided MethodInfo. Depending on /// whether the method takes arguments and on the availability /// of test case data, this method may return a single test /// or a group of tests contained in a ParameterizedMethodSuite. /// </summary> /// <param name="method">The MethodInfo for which a test is to be built</param> /// <param name="parentSuite">The test fixture being populated, or null</param> /// <returns>A Test representing one or more method invocations</returns> public IEnumerable <Test> BuildFrom(MethodInfo method, ITest parentSuite) { List <TestMethod> testCases = new List <TestMethod>(); var name = method.Name; // For Debugging List <ITestCaseFactory> sources = new List <ITestCaseFactory>( (ITestCaseFactory[])method.GetCustomAttributes(typeof(ITestCaseFactory), false)); // See if we need to add a CombinatorialAttribute for parameterized data var parameters = method.GetParameters(); bool hasParamData = parameters.Any(param => param.IsDefined(typeof(IParameterDataSource), false)); if (hasParamData) { bool hasStrategy = sources.Any(source => source is CombiningStrategyAttribute); if (!hasStrategy) { sources.Add(new CombinatorialAttribute()); } } foreach (ITestCaseFactory source in sources) { foreach (ITestCaseData testCase in source.GetTestCasesFor(method)) { var parameterSet = testCase as TestCaseParameters; if (parameterSet == null) { parameterSet = new TestCaseParameters(testCase); } testCases.Add(BuildTestMethod(method, parentSuite, parameterSet)); } } if (method.GetParameters().Length == 0) { return(testCases); } ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method); methodSuite.ApplyAttributesToTest(method); foreach (TestMethod testCase in testCases) { methodSuite.Add(testCase); } return(new [] { methodSuite }); }
public Test BuildParameterizedMethodSuite(MethodInfo method, Test parentSuite) { ParameterizedMethodSuite parameterizedMethodSuite = new ParameterizedMethodSuite(method); parameterizedMethodSuite.ApplyCommonAttributes(method); foreach (ITestCaseData item in testCaseProvider.GetTestCasesFor(method)) { ParameterSet parameterSet = item as ParameterSet; if (parameterSet == null) { parameterSet = new ParameterSet(item); } TestMethod test = BuildSingleTestMethod(method, parentSuite, parameterSet); parameterizedMethodSuite.Add(test); } return(parameterizedMethodSuite); }
private static TestCollection GetSteps(ParameterizedMethodSuite methodSuite) { var collection = new TestCollection(); collection.Name = methodSuite.TestName.Name; foreach (var test1 in methodSuite.Tests) { var method = test1 as TestMethod; if (method != null) { if (collection.Tests.All(test => test.Fullname != method.TestName.FullName)) { var testDefinition = new TestDefinition(); testDefinition.Fullname = method.TestName.FullName; testDefinition.Name = method.TestName.Name; collection.Add(testDefinition); } } } return(collection); }
/// <summary> /// Builds a ParameterizedMethodSuite containing individual test cases. /// </summary> /// <param name="method">The MethodInfo for which a test is to be built.</param> /// <param name="tests">The list of test cases to include.</param> /// <returns>A ParameterizedMethodSuite populated with test cases</returns> private Test BuildParameterizedMethodSuite(MethodInfo method, IEnumerable<TestMethod> tests) { ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method); methodSuite.ApplyAttributesToTest(method); foreach (TestMethod test in tests) methodSuite.Add(test); return methodSuite; }
/// <summary> /// Builds a ParameterizedMetodSuite containing individual /// test cases for each set of parameters provided for /// this method. /// </summary> /// <param name="method">The MethodInfo for which a test is to be built</param> /// <returns>A ParameterizedMethodSuite populated with test cases</returns> public static Test BuildParameterizedMethodSuite(MethodInfo method, Test parentSuite) { ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method); NUnitFramework.ApplyCommonAttributes(method, methodSuite); if (parentSuite != null) { if (parentSuite.RunState == RunState.NotRunnable && methodSuite.RunState != RunState.NotRunnable) { methodSuite.RunState = RunState.NotRunnable; methodSuite.IgnoreReason = parentSuite.IgnoreReason; } if (parentSuite.RunState == RunState.Ignored && methodSuite.RunState != RunState.Ignored && methodSuite.RunState != RunState.NotRunnable) { methodSuite.RunState = RunState.Ignored; methodSuite.IgnoreReason = parentSuite.IgnoreReason; } } foreach (object source in CoreExtensions.Host.TestCaseProviders.GetTestCasesFor(method, parentSuite)) { ParameterSet parms; if (source == null) { parms = new ParameterSet(); parms.Arguments = new object[] { null }; } else { parms = source as ParameterSet; } if (parms == null) { if (source.GetType().GetInterface("NUnit.Framework.ITestCaseData") != null) { parms = ParameterSet.FromDataSource(source); } else { parms = new ParameterSet(); ParameterInfo[] parameters = method.GetParameters(); Type sourceType = source.GetType(); if (parameters.Length == 1 && parameters[0].ParameterType.IsAssignableFrom(sourceType)) { parms.Arguments = new object[] { source } } ; else if (source is object[]) { parms.Arguments = (object[])source; } else if (source is Array) { Array array = (Array)source; if (array.Rank == 1) { parms.Arguments = new object[array.Length]; for (int i = 0; i < array.Length; i++) { parms.Arguments[i] = (object)array.GetValue(i); } } } else { parms.Arguments = new object[] { source } }; } } TestMethod test = BuildSingleTestMethod(method, parentSuite, parms); methodSuite.Add(test); } return(methodSuite); }
/// <summary> /// Get Testcase with Test case attributes /// </summary> /// <param name="method">The MethodInfo object.</param> public ArrayList GetTestCasesWithTestCaseAttribute(MethodInfo method) { ArrayList testCaseCollection = new ArrayList(); testMethods = Reflect.IsAsyncMethod(method) ? new NUnitAsyncTestMethod(method) : new NUnitTestMethod(method); ParameterizedMethodSuite methodSuite = new ParameterizedMethodSuite(method); NUnitFramework.ApplyCommonAttributes(method, methodSuite); IEnumerable ParameterList = ParamProvider.GetTestCasesFor(method); testCaseCollection.Add(testMethods.FixtureType.FullName + "." + method.Name); foreach (object source in ParameterList) { ParameterSet parms; if (source == null) { parms = new ParameterSet(); parms.Arguments = new object[] { null }; } else { parms = source as ParameterSet; } if (parms == null) { if (source.GetType().GetInterface("NUnit.Framework.ITestCaseData") != null) { parms = ParameterSet.FromDataSource(source); } else { parms = new ParameterSet(); ParameterInfo[] parameters = method.GetParameters(); Type sourceType = source.GetType(); if (parameters.Length == 1 && parameters[0].ParameterType.IsAssignableFrom(sourceType)) { parms.Arguments = new object[] { source } } ; else if (source is object[]) { parms.Arguments = (object[])source; } else if (source is Array) { Array array = (Array)source; if (array.Rank == 1) { parms.Arguments = new object[array.Length]; for (int i = 0; i < array.Length; i++) { parms.Arguments[i] = (object)array.GetValue(i); } } } else { parms.Arguments = new object[] { source } }; } } TestMethod testMethod = NUnit.Core.Builders.NUnitTestCaseBuilder.BuildSingleTestMethod(method, null, parms); testCaseCollection.Add(testMethod.TestName.FullName); } return(testCaseCollection); }