private UnitTestResult[] ParseTestList(NUnit.Core.Test test, string currentAssemblyPath) { if (test.IsSuite) { var tests = new List <UnitTestResult> (); foreach (var obj in test.Tests) { if (obj is TestAssembly && File.Exists((obj as TestAssembly).TestName.FullName)) { currentAssemblyPath = (obj as TestAssembly).TestName.FullName; } if (obj is NUnit.Core.Test) { var results = ParseTestList(obj as NUnit.Core.Test, currentAssemblyPath); tests.AddRange(results); } } return(tests.ToArray()); } else { return(new[] { CreateNewTestResult(test as TestMethod, currentAssemblyPath) }); } }
public Test Decorate(Test test, MemberInfo member) { if (decorateTestSpecification.IsSatisfiedBy(test)) return nspecTestMethodBuilder.Build((TestMethod) test); return test; }
public void GivenClassWithBDDTestFixtureAttributeWhenBuildFromIsCalled() { _mockTestDescriber = new Mock<ITestDescriber>(); var bddTestCaseBuilder = new BDDTestCaseBuilder(new Mock<IReflectionProvider>().Object, _mockTestDescriber.Object); var methodInfo = typeof (BDDTestFixtureTestClass).GetMethod("TestMethod1"); _returnedTestMethod = bddTestCaseBuilder.BuildFrom(methodInfo); }
public void TestStarted(TestCase testCase) { currentTestName = testCase.FullName; // if ( options.labels ) // writer.WriteLine("***** {0}", testCase.FullName ); // else if ( !options.xmlConsole ) // Console.Write("."); }
// this function is extract from NUnitFramework.ApplyCommonAttributes public static void ApplyCategoryToTest(string category, Test test) { test.Categories.Add(category); if (category.IndexOfAny(new char[] { ',', '!', '+', '-' }) >= 0) { test.RunState = RunState.NotRunnable; test.IgnoreReason = "Category name must not contain ',', '!', '+' or '-'"; } }
public Test Decorate(Test test, MemberInfo memberInfo) { if (test.GetType() == typeof(NUnitTestMethod)) { if(Reflect.GetAttributes(((NUnitTestMethod)test).Method, NUnitFramework.IgnoreAttribute, true).Length == 0) return new TestMethodWrapper((NUnitTestMethod) test); } return test; }
public TestT BuildFrom(MethodInfo method, TestT parentSuite) { TestSuite testT = new TestSuite(method.Name); NUnitFramework.ApplyCommonAttributes(method, testT); ArrayList hierachyNodeList = new ArrayList(); foreach (ProviderReference reference in GetBuildersFor(method, parentSuite)) { System.Collections.Specialized.ListDictionary contextProperties = new System.Collections.Specialized.ListDictionary(); //테스트 함수에 지정된 특성값을 계층노드의 속성으로 복사합니다. foreach (DictionaryEntry entry in testT.Properties) { if ((string)entry.Key != DESCRIPTION && (string)entry.Key != CATEGORIES) { contextProperties[entry.Key] = entry.Value; } } HierachyNode baseNode = new HierachyNode(method.Name); baseNode = reference.GetInstance(baseNode, contextProperties) as HierachyNode; if (baseNode != null) { hierachyNodeList.Add(baseNode); } } ArrayList testSuiteList = new ArrayList(); foreach (HierachyNode hierachyNode in hierachyNodeList) { TestSuite testSuite = new TestSuite(hierachyNode.Name); this.BuildTestSuiteTree(method, ref testSuite, hierachyNode); testSuiteList.Add(testSuite); } if (testSuiteList.Count > 0) { if (testSuiteList.Count == 1) { testT = testSuiteList[0] as TestSuite; } else { testT = new TestSuite(method.Name); NUnitFramework.ApplyCommonAttributes(method, testT); foreach (TestSuite testSuite in testSuiteList) { testT.Add(testSuite); } } } return testT; }
private void ToUnitTestResult(NUnit.Core.Test test) { if (test.IsSuite) { ToUnitTestResult(test.Tests); } else { UpdateTest(test.UnitTestResult()); } }
private static RetryAttribute GetRetryAttribute(MemberInfo member, Test testMethodSuite) { var retryAttr = GetRetryAttribute(member); if (retryAttr == null && testMethodSuite.FixtureType != null) { retryAttr = GetRetryAttribute(testMethodSuite.FixtureType); } return retryAttr; }
public bool HasTestCasesFor(MethodInfo method, TestT suite) { if (Reflect.HasAttribute( method, typeof(TestCaseSourceWithPropertiesAttribute).FullName, false)) { return true; } return false; }
public static UnitTestResult UnitTestResult(this NUnit.Core.Test test) { return(new UnitTestResult() { Message = "", StackTrace = "", Duration = 0, Test = test.UnitTestInfo(), AssemblyPath = currentAssemblyPath }); }
public TestResult Run(string test_name, EventListener listener, ITestFilter filter) { try { Type test_type = Type.GetType(test_name, true); NUnit.Core.Test test = builder.BuildFrom(test_type); TestResult result = test.Run(listener, filter); return(result); } catch (Exception ex) { Console.WriteLine("RUN EX: {0}", ex); throw; } }
public IEnumerable GetTestCasesFor(MethodInfo method, TestT parentSuite) { ArrayList list = new ArrayList(); foreach (ProviderReference reference in GetSourcesFor(method, parentSuite)) { foreach (object obj in (IEnumerable)reference.GetInstance(parentSuite.Properties)) { list.Add(obj); } } return list; }
public Test Decorate(Test test, MemberInfo member) { if ( member == null ) return test; TestCase testCase = test as TestCase; if ( testCase == null ) return test; System.Attribute[] ignoreAttr = Reflect.GetAttributes( member, IgnoreBrowserAttributeTypeFullName, true ); if ( ignoreAttr == null ) return test; // A test case might be ignored in more than one browser foreach (System.Attribute attr in ignoreAttr) { object propVal = Reflect.GetPropertyValue(attr, "Value", BindingFlags.Public | BindingFlags.Instance); object reasonValue = Reflect.GetPropertyValue(attr, "Reason", BindingFlags.Public | BindingFlags.Instance); if (propVal == null) { return test; } string ignoreReason = "Ignoring browser " + EnvironmentManager.Instance.Browser.ToString() + "."; if (reasonValue != null) { ignoreReason = ignoreReason + " " + reasonValue.ToString(); } Browser browser = (Browser)propVal; if (browser.Equals(EnvironmentManager.Instance.Browser) || browser.Equals(Browser.All) || IsRemoteInstanceOfBrowser(browser)) { testCase.RunState = RunState.Ignored; testCase.IgnoreReason = ignoreReason; return testCase; } } return test; }
public Test Decorate(Test test, MemberInfo member) { var retryAttr = GetRetryAttribute(member, test); if (retryAttr == null) return test; if (test is NUnitTestMethod) { return new RetriedTestMethod( (NUnitTestMethod)test, retryAttr.Times, retryAttr.RequiredPassCount); } if (!(test is ParameterizedMethodSuite)) return test; var testMethodSuite = (ParameterizedMethodSuite)test; System.Collections.IList newTests = new List<Test>(); foreach (Test childTest in testMethodSuite.Tests) { if (childTest is NUnitTestMethod) { var oldTest = (NUnitTestMethod)childTest; var newTest = new RetriedTestMethod( oldTest, retryAttr.Times, retryAttr.RequiredPassCount); newTests.Add(newTest); } else { newTests.Add(childTest); } } testMethodSuite.Tests.Clear(); foreach (Test newTest in newTests) { testMethodSuite.Add(newTest); } return testMethodSuite; }
/// <summary> /// Return an IEnumerable providing test cases for use in /// running a parameterized test. /// </summary> /// <param name="method"></param> /// <param name="parentSuite"></param> /// <returns></returns> public IEnumerable GetTestCasesFor(MethodInfo method, Test parentSuite) { ArrayList parameterList = new ArrayList(); var attributes = Reflect.GetAttributes(method, Constants.AutoDataAttribute, false); foreach (DataAttribute attr in attributes) { foreach (var arguments in attr.GetData(method)) { ParameterSet parms = new ParameterSet(); parms.Arguments = arguments; parameterList.Add(parms); } } return parameterList; }
private void ToUnitTestResult(NUnit.Core.Test test) { if (test.IsSuite) { ToUnitTestResult(test.Tests); } else { if (test is TestMethod) { var tm = test as TestMethod; if (tm.Method.DeclaringType != tm.Method.ReflectedType) { return; } } UpdateTest(test.UnitTestResult()); } }
public Test Decorate(Test test, MemberInfo member) { if (test is NUnitTestMethod) { var testMethod = (NUnitTestMethod)test; var attrs = member.GetCustomAttributes(typeof(RetryAttribute), true); if (testMethod.FixtureType != null) { var fixtureAttrs = testMethod.FixtureType.GetCustomAttributes(typeof(RetryAttribute), true).ToArray(); if (fixtureAttrs.Length > 0) { var retryAttr = (fixtureAttrs[0] as RetryAttribute); if (retryAttr != null) { test = new RetriedTestMethod( testMethod.Method, retryAttr.Times, retryAttr.RequiredPassCount); } } } if (attrs.Any()) { var retryAttr = (attrs.First() as RetryAttribute); if (retryAttr == null) { return test; } test = new RetriedTestMethod(testMethod.Method, retryAttr.Times, retryAttr.RequiredPassCount); } } return test; }
public Test Decorate(Test test, MemberInfo member) { if ( member == null ) return test; TestCase testCase = test as TestCase; if ( testCase == null ) return test; System.Attribute[] ignoreAttr = Reflect.GetAttributes( member, IgnoreAttributeType, true ); if ( ignoreAttr == null ) return test; // A test case might be ignored in more than one browser foreach (System.Attribute attr in ignoreAttr) { // TODO(andre.nogueira): Check if a reason has been entered // in the annotation, and if so include it in IgnoreReason. object propVal = Reflect.GetPropertyValue(attr, "Value", BindingFlags.Public | BindingFlags.Instance); if (propVal == null) return test; Browser browser = (Browser)propVal; if (browser.Equals(Environment.Instance.Browser) || browser.Equals(Browser.ALL)) { testCase.RunState = RunState.Ignored; testCase.IgnoreReason = "Ignoring browser " + Environment.Instance.Browser.ToString() + "."; return testCase; } } return test; }
private static IList GetSourcesFor(MethodInfo method, TestT parent) { ArrayList providerReferenceList = new ArrayList(); foreach (Attribute attribute in Reflect.GetAttributes( method, typeof(TestCaseSourceWithPropertiesAttribute).FullName, false)) { Type sourceType = Reflect.GetPropertyValue(attribute, "ProviderType") as Type; string sourceName = Reflect.GetPropertyValue(attribute, "MemberName") as string; if (sourceType == null) { providerReferenceList.Add( new ProviderReference(method.ReflectedType, sourceName)); } else { providerReferenceList.Add( new ProviderReference(sourceType, sourceName)); } } return providerReferenceList; }
/// <summary> /// Modify a newly constructed test based on a type or method by /// applying any of NUnit's common attributes. /// </summary> /// <param name="member">The type or method from which the test was constructed</param> /// <param name="test">The test to which the attributes apply</param> public static void ApplyCommonAttributes(MemberInfo member, Test test) { ApplyCommonAttributes(Reflect.GetAttributes(member, false), test); }
public void setup() { specification = new DecorateTestSpecification(); test = NUnitSubstitute.ForTest(); }
public AddinTestMethod(ConeMethodThunk thunk, Test suite, TestExecutor testExecutor, string name) : base(suite, testExecutor, name) { this.thunk = thunk; }
public bool CanBuildFrom(MethodInfo method, TestT suite) { if (Reflect.HasAttribute(method, typeof(HierachicalTestCaseAttribute).FullName, false)) { return true; } return false; }
public NativeTest(Test test) { _test = test; }
/// <summary> /// Unload all tests previously loaded /// </summary> public void Unload() { log.Debug("Unloading"); this.test = null; // All for now }
public virtual bool IsSatisfiedBy(Test test) { return test.TestType == TestMethodTestType && typeof(Spec).IsAssignableFrom(test.FixtureType); }
/// <summary> /// Modify a newly constructed test based on an assembly by applying /// any of NUnit's common attributes. /// </summary> /// <param name="assembly">The assembly from which the test was constructed</param> /// <param name="test">The test to which the attributes apply</param> public static void ApplyCommonAttributes(Assembly assembly, Test test) { ApplyCommonAttributes(Reflect.GetAttributes(assembly, false), test); }
/// <summary> /// Modify a newly constructed test by applying any of NUnit's common /// attributes, based on an input array of attributes. This method checks /// for all attributes, relying on the fact that specific attributes can only /// occur on those constructs on which they are allowed. /// </summary> /// <param name="attributes">An array of attributes possibly including NUnit attributes /// <param name="test">The test to which the attributes apply</param> public static void ApplyCommonAttributes(Attribute[] attributes, Test test) { foreach (Attribute attribute in attributes) { Type attributeType = attribute.GetType(); string attributeName = attributeType.FullName; bool isValid = test.RunState != RunState.NotRunnable; switch (attributeName) { case TestFixtureAttribute: case TestAttribute: if (test.Description == null) { test.Description = GetDescription(attribute); } break; case DescriptionAttribute: test.Description = GetDescription(attribute); break; case ExplicitAttribute: if (isValid) { test.RunState = RunState.Explicit; test.IgnoreReason = GetIgnoreReason(attribute); } break; case IgnoreAttribute: if (isValid) { test.RunState = RunState.Ignored; test.IgnoreReason = GetIgnoreReason(attribute); } break; case PlatformAttribute: PlatformHelper pHelper = new PlatformHelper(); if (isValid && !pHelper.IsPlatformSupported(attribute)) { test.RunState = RunState.Skipped; test.IgnoreReason = GetIgnoreReason(attribute); if (test.IgnoreReason == null) { test.IgnoreReason = pHelper.Reason; } } break; case CultureAttribute: CultureDetector cultureDetector = new CultureDetector(); if (isValid && !cultureDetector.IsCultureSupported(attribute)) { test.RunState = RunState.Skipped; test.IgnoreReason = cultureDetector.Reason; } break; case RequiredAddinAttribute: string required = (string)Reflect.GetPropertyValue(attribute, PropertyNames.RequiredAddin); if (!IsAddinAvailable(required)) { test.RunState = RunState.NotRunnable; test.IgnoreReason = string.Format("Required addin {0} not available", required); } break; case "System.STAThreadAttribute": test.Properties.Add("APARTMENT_STATE", System.Threading.ApartmentState.STA); break; case "System.MTAThreadAttribute": test.Properties.Add("APARTMENT_STATE", System.Threading.ApartmentState.MTA); break; default: if (Reflect.InheritsFrom(attributeType, CategoryAttribute)) { test.Categories.Add(Reflect.GetPropertyValue(attribute, PropertyNames.CategoryName)); } else if (Reflect.InheritsFrom(attributeType, PropertyAttribute)) { IDictionary props = (IDictionary)Reflect.GetPropertyValue(attribute, PropertyNames.Properties); if (props != null) { foreach (DictionaryEntry entry in props) { test.Properties.Add(entry.Key, entry.Value); } } } break; } } }
/// <summary> /// Determine whether any test cases are available for a parameterized method. /// </summary> /// <param name="method">A MethodInfo representing a parameterized test</param> /// <param name="suite">A Suite representing a NUnit TestSuite</param> /// <returns>True if any cases are available, otherwise false.</returns> public bool HasTestCasesFor(MethodInfo method, Test suite) { return HasTestCasesFor(method); }