/// <summary> /// Initializes an instance of <see cref="InconclusiveTestCase"/>. /// </summary> /// <param name="testCase">Original test case.</param> public InconclusiveTestCase(NUnitTestMethod testCase) : base(testCase.Method) { NUnitFramework.ApplyCommonAttributes(testCase.Method, this); NUnitFramework.ApplyExpectedExceptionAttribute(testCase.Method, this); // Copy all the attributes of the original test this.BuilderException = testCase.BuilderException; this.Categories = testCase.Categories; this.Description = testCase.Description; this.ExceptionProcessor = testCase.ExceptionProcessor; this.Fixture = testCase.Fixture; this.IgnoreReason = testCase.IgnoreReason; this.Parent = testCase.Parent; this.Properties = testCase.Properties; this.RunState = testCase.RunState; this.TestName.Name = testCase.TestName.Name; this.TestName.FullName = testCase.TestName.FullName; this.TestName.RunnerID = testCase.TestName.RunnerID; this.TestName.TestID = testCase.TestName.TestID; this.setUpMethods = GetFieldValue <MethodInfo[]>(typeof(TestMethod), testCase, "setUpMethods"); this.tearDownMethods = GetFieldValue <MethodInfo[]>(typeof(TestMethod), testCase, "tearDownMethods"); this.actions = GetFieldValue <TestAction[]>(typeof(TestMethod), testCase, "actions"); this.suiteActions = GetFieldValue <TestAction[]>(typeof(TestMethod), testCase, "suiteActions"); this.SetFieldValue("arguments", GetFieldValue <object[]>(typeof(TestMethod), testCase, "arguments")); this.SetFieldValue("expectedResult", GetFieldValue <object>(typeof(TestMethod), testCase, "expectedResult")); this.SetFieldValue("hasExpectedResult", GetFieldValue <bool>(typeof(TestMethod), testCase, "hasExpectedResult")); }
private Test BuildSingleFixture(Type type, Attribute attr) { object[] arguments = null; if (attr != null) { arguments = (object[])Reflect.GetPropertyValue(attr, "Arguments"); #if NET_2_0 if (type.ContainsGenericParameters) { Type[] typeArgs = (Type[])Reflect.GetPropertyValue(attr, "TypeArgs"); if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } #endif } this.fixture = new NUnitTestFixture(type, arguments); CheckTestFixtureIsValid(fixture); NUnitFramework.ApplyCommonAttributes(type, fixture); AddTestCases(type); if (this.fixture.RunState != RunState.NotRunnable && this.fixture.TestCount == 0) { this.fixture.RunState = RunState.NotRunnable; this.fixture.IgnoreReason = fixture.TestName.Name + " does not have any tests"; } return(this.fixture); }
////private MethodInfo _methodinfo; /// <summary> /// Constructor to map method with this class. /// </summary> /// <param name="method">Method in test fixture without parameters.</param> public WalmartTestMethod(MethodInfo method) : base(method) { NUnitFramework.ApplyCommonAttributes(method, this); NUnitFramework.ApplyExpectedExceptionAttribute(method, this); var categories = new List <string>(); var className = method.DeclaringType; categories.ForEach(c => Categories.Add(c)); var notReadyAttr = method.GetCustomAttributes(typeof(NotReadyAttribute), true); if (notReadyAttr.Any()) { Categories.Add("NotReady"); } ////Add EUAT as Category var regressionAttr = method.GetCustomAttributes(typeof(RegressionAttribute), true); if (regressionAttr.Any()) { Categories.Add("Regression"); } ////Add ToFix as Category var tofixAttr = method.GetCustomAttributes(typeof(ToFixAttribute), true); if (tofixAttr.Any()) { Categories.Add("ToFix"); } }
public Test BuildFrom(Type type) { var testSuite = new TestSuite(type.FullName); testSuite.Add(new ConcordionTest(type)); NUnitFramework.ApplyCommonAttributes(type, testSuite); return(testSuite); }
public static TestSuite CreateTestSuite(MethodInfo method) { var suite = new DecompilationTestSuite(method); NUnitFramework.ApplyCommonAttributes(method, suite); PopulateTestSuite(method, suite); return(suite); }
public Test BuildFrom(Type type) { var testFixture = new ConcordionTestFixture(type); testFixture.Add(new ConcordionTest(type)); NUnitFramework.ApplyCommonAttributes(type, testFixture); return(testFixture); }
public Test BuildFrom(Type type) { NativeTestFactory nativeTestFactory = new NativeTestFactory(); SpecificationBuilder.BuildTestFixture(type, nativeTestFactory, new GlobalSetupOwner()); var result = nativeTestFactory.RootTest.GetNative() as Test; NUnitFramework.ApplyCommonAttributes(type.GetCustomAttributes(false).Cast <Attribute>().ToArray(), result); return(result); }
public RowTestSuite CreateRowTestSuite(MethodInfo method) { if (method == null) { throw new ArgumentNullException("method"); } RowTestSuite testSuite = new RowTestSuite(method); NUnitFramework.ApplyCommonAttributes(method, testSuite); return(testSuite); }
private Test BuildSingleFixture(Type type, Attribute attr) { object[] arguments = null; IList categories = null; if (attr != null) { arguments = (object[])Reflect.GetPropertyValue(attr, "Arguments"); categories = Reflect.GetPropertyValue(attr, "Categories") as IList; #if CLR_2_0 || CLR_4_0 if (type.ContainsGenericParameters) { Type[] typeArgs = (Type[])Reflect.GetPropertyValue(attr, "TypeArgs"); if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } #endif } this.fixture = new NUnitTestFixture(type, arguments); CheckTestFixtureIsValid(fixture); NUnitFramework.ApplyCommonAttributes(type, fixture); if (categories != null) { foreach (string category in categories) { fixture.Categories.Add(category); } } if (fixture.RunState == RunState.Runnable && attr != null) { object objIgnore = Reflect.GetPropertyValue(attr, "Ignore"); if (objIgnore != null && (bool)objIgnore == true) { fixture.RunState = RunState.Ignored; fixture.IgnoreReason = (string)Reflect.GetPropertyValue(attr, "IgnoreReason"); } } AddTestCases(type); return(this.fixture); }
public static CecilTestSuite CreateTestSuite(MethodInfo method) { if (method == null) { throw new ArgumentNullException("method"); } var suite = new CecilTestSuite(method); NUnitFramework.ApplyCommonAttributes(method, suite); PopulateTestSuite(method, suite); return(suite); }
/// <summary> /// Builds a single NUnitTestMethod, either as a child of the fixture /// or as one of a set of test cases under a ParameterizedTestMethodSuite. /// </summary> /// <param name="method">The MethodInfo from which to construct the TestMethod</param> /// <param name="parms">The ParameterSet to be used, or null</param> /// <returns></returns> public static NUnitTestMethod BuildSingleTestMethod(MethodInfo method, ParameterSet parms) { NUnitTestMethod testMethod = new NUnitTestMethod(method); if (CheckTestMethodSignature(testMethod, parms)) { NUnitFramework.ApplyCommonAttributes(method, testMethod); NUnitFramework.ApplyExpectedExceptionAttribute(method, testMethod); } if (parms != null) { // NOTE: After the call to CheckTestMethodSignature, the Method // property of testMethod may no longer be the same as the // original MethodInfo, so we reassign it here. method = testMethod.Method; if (parms.TestName != null) { testMethod.TestName.Name = parms.TestName; testMethod.TestName.FullName = method.ReflectedType.FullName + "." + parms.TestName; } else if (parms.Arguments != null) { string name = MethodHelper.GetDisplayName(method, parms.Arguments); testMethod.TestName.Name = name; testMethod.TestName.FullName = method.ReflectedType.FullName + "." + name; } if (parms.ExpectedExceptionName != null) { testMethod.exceptionProcessor = new ExpectedExceptionProcessor(testMethod, parms); } foreach (string key in parms.Properties.Keys) { testMethod.Properties.Add(key, parms.Properties[key]); } // Description is stored in parms.Properties if (parms.Description != null) { testMethod.Description = parms.Description; } } return(testMethod); }
private TestSuite BuildTestAssembly(string assemblyName, IList fixtures, bool autoSuites) { TestSuite testAssembly = new TestAssembly(assemblyName); if (autoSuites) { NamespaceTreeBuilder treeBuilder = new NamespaceTreeBuilder(testAssembly); treeBuilder.Add(fixtures); testAssembly = treeBuilder.RootSuite; } else { foreach (TestSuite fixture in fixtures) { if (fixture != null) { if (fixture is SetUpFixture) { fixture.RunState = RunState.NotRunnable; fixture.IgnoreReason = "SetUpFixture cannot be used when loading tests as a flat list of fixtures"; } testAssembly.Add(fixture); } } } if (fixtures.Count == 0) { testAssembly.RunState = RunState.NotRunnable; testAssembly.IgnoreReason = "Has no TestFixtures"; } NUnitFramework.ApplyCommonAttributes(assembly, testAssembly); testAssembly.Properties["_PID"] = System.Diagnostics.Process.GetCurrentProcess().Id; testAssembly.Properties["_APPDOMAIN"] = AppDomain.CurrentDomain.FriendlyName; // TODO: Make this an option? Add Option to sort assemblies as well? testAssembly.Sort(); return(testAssembly); }
TestFixture BuildFixture(Type type, ParameterizedTestFixtureAttribute attr, object parameter) { var categories = (IList <string>)Reflect.GetPropertyValue(attr, "Categories"); Type fixtureType; if (type.IsGenericType) { fixtureType = type.MakeGenericType(attr.Type); } else { fixtureType = type; } var parameterizedFixture = typeof(ParameterizedTestFixture <>).MakeGenericType(attr.Type); var fixture = (NUnitTestFixture)Reflect.Construct(parameterizedFixture, new object[] { fixtureType, Configuration, parameter }); NUnitFramework.ApplyCommonAttributes(fixtureType, fixture); if (categories != null) { foreach (string category in categories) { fixture.Categories.Add(category); } } if (fixture.RunState == RunState.Runnable && attr != null) { var objIgnore = Reflect.GetPropertyValue(attr, "Ignore"); if (objIgnore != null && (bool)objIgnore == true) { fixture.RunState = RunState.Ignored; fixture.IgnoreReason = (string)Reflect.GetPropertyValue(attr, "IgnoreReason"); } } AddTestCases(fixture); return(fixture); }
private TestSuite BuildTestAssembly(string assemblyName, IList fixtures, bool autoSuites) { TestSuite testAssembly = new TestSuite(assemblyName); if (autoSuites) { NamespaceTreeBuilder treeBuilder = new NamespaceTreeBuilder(testAssembly); treeBuilder.Add(fixtures); testAssembly = treeBuilder.RootSuite; } else { foreach (TestSuite fixture in fixtures) { if (fixture is SetUpFixture) { fixture.RunState = RunState.NotRunnable; fixture.IgnoreReason = "SetUpFixture cannot be used when loading tests as a flat list of fixtures"; } testAssembly.Add(fixture); } } if (fixtures.Count == 0) { testAssembly.RunState = RunState.NotRunnable; testAssembly.IgnoreReason = "Has no TestFixtures"; } NUnitFramework.ApplyCommonAttributes(assembly, testAssembly); // TODO: Make this an option? Add Option to sort assemblies as well? testAssembly.Sort(); return(testAssembly); }
/// <summary> /// Builds a single NUnitTestMethod, either as a child of the fixture /// or as one of a set of test cases under a ParameterizedTestMethodSuite. /// </summary> /// <param name="method">The MethodInfo from which to construct the TestMethod</param> /// <param name="parms">The ParameterSet to be used, or null</param> /// <returns></returns> public static NUnitTestMethod BuildSingleTestMethod(MethodInfo method, Test parentSuite, ParameterSet parms) { NUnitTestMethod testMethod = new NUnitTestMethod(method); string prefix = method.ReflectedType.FullName; if (parentSuite != null) { prefix = parentSuite.TestName.FullName; testMethod.TestName.FullName = prefix + "." + testMethod.TestName.Name; } if (CheckTestMethodSignature(testMethod, parms)) { if (parms == null) { NUnitFramework.ApplyCommonAttributes(method, testMethod); } NUnitFramework.ApplyExpectedExceptionAttribute(method, testMethod); } if (parms != null) { // NOTE: After the call to CheckTestMethodSignature, the Method // property of testMethod may no longer be the same as the // original MethodInfo, so we reassign it here. method = testMethod.Method; if (parms.TestName != null) { testMethod.TestName.Name = parms.TestName; testMethod.TestName.FullName = prefix + "." + parms.TestName; } else if (parms.OriginalArguments != null) { string name = MethodHelper.GetDisplayName(method, parms.OriginalArguments); testMethod.TestName.Name = name; testMethod.TestName.FullName = prefix + "." + name; } if (parms.Ignored) { testMethod.RunState = RunState.Ignored; testMethod.IgnoreReason = parms.IgnoreReason; } else if (parms.Explicit) { testMethod.RunState = RunState.Explicit; } if (parms.ExpectedExceptionName != null) { testMethod.exceptionProcessor = new ExpectedExceptionProcessor(testMethod, parms); } foreach (string key in parms.Properties.Keys) { testMethod.Properties[key] = parms.Properties[key]; } // Description is stored in parms.Properties if (parms.Description != null) { testMethod.Description = parms.Description; } } //if (testMethod.BuilderException != null && testMethod.RunState != RunState.NotRunnable) //{ // testMethod.RunState = RunState.NotRunnable; // testMethod.IgnoreReason = testMethod.BuilderException.Message; //} if (parentSuite != null) { if (parentSuite.RunState == RunState.NotRunnable && testMethod.RunState != RunState.NotRunnable) { testMethod.RunState = RunState.NotRunnable; testMethod.IgnoreReason = parentSuite.IgnoreReason; } if (parentSuite.RunState == RunState.Ignored && testMethod.RunState != RunState.Ignored && testMethod.RunState != RunState.NotRunnable) { testMethod.RunState = RunState.Ignored; testMethod.IgnoreReason = parentSuite.IgnoreReason; } } return(testMethod); }
/// <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); }
/// <summary> /// Set additional properties of the newly created test case based /// on its attributes. As implemented, the method sets the test's /// RunState, Description, Categories and Properties. /// </summary> /// <param name="method">A MethodInfo for the method being used as a test method</param> /// <param name="testCase">The test case being constructed</param> protected override void SetTestProperties(MethodInfo method, TestCase testCase) { NUnitFramework.ApplyCommonAttributes(method, testCase); NUnitFramework.ApplyExpectedExceptionAttribute(method, (TestMethod)testCase); }
public TestMethodExtension BuildSingleTestMethod(MethodInfo method, Test parentSuite, ParameterSet parms, ScreenCapture screenCapture, IDictionary properties) { //TODO : Here it doesn't support Async Await Method, BTW, the Async Await just be supported from .net 4.5 TestMethodExtension testMethod = new TestMethodExtension(method, screenCapture); string prefix = method.ReflectedType.FullName; if (parentSuite != null) { testMethod.Properties = properties; prefix = parentSuite.TestName.FullName; testMethod.TestName.FullName = prefix + "." + testMethod.TestName.Name; } if (CheckTestMethodSignature(testMethod, parms)) { if (parms == null) { NUnitFramework.ApplyCommonAttributes(method, testMethod); } NUnitFramework.ApplyExpectedExceptionAttribute(method, testMethod); } if (parms != null) { method = testMethod.Method; if (parms.TestName != null) { testMethod.TestName.Name = parms.TestName; testMethod.TestName.FullName = prefix + "." + parms.TestName; } else if (parms.OriginalArguments != null) { string name = MethodHelper.GetDisplayName(method, parms.OriginalArguments); testMethod.TestName.Name = name; testMethod.TestName.FullName = prefix + "." + name; } if (parms.Ignored) { testMethod.RunState = RunState.Ignored; testMethod.IgnoreReason = parms.IgnoreReason; } else if (parms.Explicit) { testMethod.RunState = RunState.Explicit; } foreach (string key in parms.Properties.Keys) { testMethod.Properties[key] = parms.Properties[key]; } if (parms.Description != null) { testMethod.Description = parms.Description; } } if (parentSuite != null) { if (parentSuite.RunState == RunState.NotRunnable && testMethod.RunState != RunState.NotRunnable) { testMethod.RunState = RunState.NotRunnable; testMethod.IgnoreReason = parentSuite.IgnoreReason; } if (parentSuite.RunState == RunState.Ignored && testMethod.RunState != RunState.Ignored && testMethod.RunState != RunState.NotRunnable) { testMethod.RunState = RunState.Ignored; testMethod.IgnoreReason = parentSuite.IgnoreReason; } } return(testMethod); }
private Test BuildSingleFixture(Type type, Attribute attr) { object[] arguments = null; IList categories = null; if (attr != null) { arguments = GetArgsFromAttribute(attr); categories = Reflect.GetPropertyValue(attr, "Categories") as IList; #if CLR_2_0 || CLR_4_0 if (type.ContainsGenericParameters) { Type[] typeArgs = GetTypeArgsFromAttribute(attr); if (typeArgs == null) { int cnt = 0; foreach (object o in arguments) { if (o is Type) { cnt++; } else { break; } } typeArgs = new Type[cnt]; for (int i = 0; i < cnt; i++) { typeArgs[i] = (Type)arguments[i]; } if (cnt > 0) { object[] args = new object[arguments.Length - cnt]; for (int i = 0; i < args.Length; i++) { args[i] = arguments[cnt + i]; } arguments = args; } } if (typeArgs.Length > 0 || TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs)) { type = TypeHelper.MakeGenericType(type, typeArgs); } } #endif } this.fixture = new NUnitTestFixture(type, arguments); CheckTestFixtureIsValid(fixture); NUnitFramework.ApplyCommonAttributes(type, fixture); if (categories != null) { foreach (string category in categories) { fixture.Categories.Add(category); } } if (fixture.RunState == RunState.Runnable && attr != null) { object objIgnore = Reflect.GetPropertyValue(attr, "Ignore"); if (objIgnore != null && (bool)objIgnore == true) { fixture.RunState = RunState.Ignored; fixture.IgnoreReason = (string)Reflect.GetPropertyValue(attr, "IgnoreReason"); } } AddTestCases(type); return(this.fixture); }
/// <summary> /// Method that sets properties of the test suite based on the /// information in the provided Type. /// </summary> /// <param name="type">The type to examine</param> /// <param name="suite">The test suite being constructed</param> protected override void SetTestSuiteProperties(Type type, TestSuite suite) { base.SetTestSuiteProperties(type, suite); NUnitFramework.ApplyCommonAttributes(type, suite); }
/// <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); }