public TestCaseElement (TestMethod testCase, TouchRunner runner) : base (testCase, runner) { Caption = testCase.Name; Value = "NotExecuted"; this.Tapped += async delegate { if (!Runner.OpenWriter (Test.FullName)) return; var suite = (testCase.Parent as TestSuite); var context = TestExecutionContext.CurrentContext; context.TestObject = Reflect.Construct (testCase.Method.ReflectedType, null); await suite.GetOneTimeSetUpCommand ().Execute (context); await Run (); await suite.GetOneTimeTearDownCommand ().Execute (context); Runner.CloseWriter (); // display more details on (any) failure (but not when ignored) if ((TestCase.RunState == RunState.Runnable) && !Result.IsSuccess ()) { var root = new RootElement ("Results") { new Section () { new TestResultElement (Result) } }; var dvc = new DialogViewController (root, true) { Autorotate = true }; runner.NavigationController.PushViewController (dvc, true); } else if (GetContainerTableView () != null) { var root = GetImmediateRootElement (); root.Reload (this, UITableViewRowAnimation.Fade); } }; }
public TestCaseElement (TestMethod test, AndroidRunner runner) : base (test, runner) { if (test.RunState == RunState.Runnable) Indicator = "..."; // hint there's more Caption = test.Name; }
/// <summary> /// Get the display name for a TestMethod and it's arguments /// </summary> /// <param name="testMethod">A TestMethod</param> /// <param name="args">Arguments to be used</param> /// <returns>The display name</returns> public string GetDisplayName(TestMethod testMethod, object[] args) { if (_fragments == null) _fragments = BuildFragmentList(_pattern); var result = new StringBuilder(); foreach (var fragment in _fragments) result.Append(fragment.GetText(testMethod, args)); return result.ToString(); }
public void SetUp() { test = new TestMethod(typeof(DummySuite).GetMethod("DummyMethod")); test.Properties.Set(PropertyNames.Description, "Test description"); test.Properties.Add(PropertyNames.Category, "Dubious"); test.Properties.Set("Priority", "low"); testResult = test.MakeTestResult(); TestSuite suite = new TestSuite(typeof(DummySuite)); suite.Properties.Set(PropertyNames.Description, "Suite description"); suite.Properties.Add(PropertyNames.Category, "Fast"); suite.Properties.Add("Value", 3); suiteResult = suite.MakeTestResult(); SimulateTestRun(); }
public void SetUp() { expectedDuration = 0.125; expectedStart = new DateTime(1968, 4, 8, 15, 05, 30, 250, DateTimeKind.Utc); expectedEnd = expectedStart.AddSeconds(expectedDuration); test = new TestMethod(typeof(DummySuite).GetMethod("DummyMethod")); test.Properties.Set(PropertyNames.Description, "Test description"); test.Properties.Add(PropertyNames.Category, "Dubious"); test.Properties.Set("Priority", "low"); testResult = test.MakeTestResult(); TestSuite suite = new TestSuite(typeof(DummySuite)); suite.Properties.Set(PropertyNames.Description, "Suite description"); suite.Properties.Add(PropertyNames.Category, "Fast"); suite.Properties.Add("Value", 3); suiteResult = suite.MakeTestResult(); SimulateTestRun(); }
public TestCaseElement (TestMethod testCase, TouchRunner runner) : base (testCase, runner) { Caption = testCase.Name; Value = "NotExecuted"; this.Tapped += delegate { if (!Runner.OpenWriter (Test.FullName)) return; Run (); Runner.CloseWriter (); // display more details on (any) failure (but not when ignored) if ((TestCase.RunState == RunState.Runnable) && !Result.IsSuccess ()) { var root = new RootElement ("Results") { new Section () { new TestResultElement (Result) } }; var dvc = new DialogViewController (root, true) { Autorotate = true }; runner.NavigationController.PushViewController (dvc, true); } }; }
/// <summary> /// Get the display name for a TestMethod and it's arguments /// </summary> /// <param name="testMethod">A TestMethod</param> /// <returns>The display name</returns> public string GetDisplayName(TestMethod testMethod) { return GetDisplayName(testMethod, null); }
public override string GetText(TestMethod testMethod, object[] args) { return testMethod.Id; }
public virtual string GetText(TestMethod testMethod, object[] args) { return GetText(testMethod.Method.MethodInfo, args); }
/// <summary> /// Get the display name for a TestMethod and its arguments /// </summary> /// <param name="testMethod">A TestMethod</param> /// <returns>The display name</returns> public string GetDisplayName(TestMethod testMethod) { return(GetDisplayName(testMethod, null)); }
public virtual string GetText(TestMethod testMethod, object[] args) { return(GetText(testMethod.Method.MethodInfo, args)); }
/// <summary> /// Get the display name for a TestMethod and it's arguments /// </summary> /// <param name="testMethod">A TestMethod</param> /// <param name="args">Arguments to be used</param> /// <returns>The display name</returns> public string GetDisplayName(TestMethod testMethod, object[] args) { var result = new StringBuilder(); foreach (var fragment in _fragments) result.Append(fragment.GetText(testMethod, args)); return result.ToString(); }
/// <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="parentSuite">The suite or fixture to which the new test will be added</param> /// <param name="parms">The ParameterSet to be used, or null</param> /// <returns></returns> private TestMethod BuildSingleTestMethod(MethodInfo method, Test parentSuite, ParameterSet parms) { TestMethod testMethod = new TestMethod(method, parentSuite); testMethod.Seed = randomizer.Next(); string prefix = method.ReflectedType.FullName; // Needed to give proper fullname to test in a parameterized fixture. // Without this, the arguments to the fixture are not included. if (parentSuite != null) { prefix = parentSuite.FullName; //testMethod.FullName = prefix + "." + testMethod.Name; } if (CheckTestMethodSignature(testMethod, parms)) { if (parms == null) testMethod.ApplyAttributesToTest(method); foreach (ICommandDecorator decorator in method.GetCustomAttributes(typeof(ICommandDecorator), true)) testMethod.CustomDecorators.Add(decorator); ExpectedExceptionAttribute[] attributes = (ExpectedExceptionAttribute[])method.GetCustomAttributes(typeof(ExpectedExceptionAttribute), false); if (attributes.Length > 0) { ExpectedExceptionAttribute attr = attributes[0]; string handlerName = attr.Handler; if (handlerName != null && GetExceptionHandler(testMethod.FixtureType, handlerName) == null) MarkAsNotRunnable( testMethod, string.Format("The specified exception handler {0} was not found", handlerName)); testMethod.CustomDecorators.Add(new ExpectedExceptionDecorator(attr.ExceptionData)); } } 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.Name = parms.TestName; testMethod.FullName = prefix + "." + parms.TestName; } else if (parms.OriginalArguments != null) { string name = MethodHelper.GetDisplayName(method, parms.OriginalArguments); testMethod.Name = name; testMethod.FullName = prefix + "." + name; } parms.ApplyToTest(testMethod); } return testMethod; }
private static bool MarkAsNotRunnable(TestMethod testMethod, string reason) { testMethod.RunState = RunState.NotRunnable; testMethod.Properties.Set(PropertyNames.SkipReason, reason); return false; }
/// <summary> /// Helper method that checks the signature of a TestMethod and /// any supplied parameters to determine if the test is valid. /// /// Currently, NUnitTestMethods are required to be public, /// non-abstract methods, either static or instance, /// returning void. They may take arguments but the values must /// be provided or the TestMethod is not considered runnable. /// /// Methods not meeting these criteria will be marked as /// non-runnable and the method will return false in that case. /// </summary> /// <param name="testMethod">The TestMethod to be checked. If it /// is found to be non-runnable, it will be modified.</param> /// <param name="parms">Parameters to be used for this test, or null</param> /// <returns>True if the method signature is valid, false if not</returns> private static bool CheckTestMethodSignature(TestMethod testMethod, ParameterSet parms) { if (testMethod.Method.IsAbstract) { return MarkAsNotRunnable(testMethod, "Method is abstract"); } if (!testMethod.Method.IsPublic) { return MarkAsNotRunnable(testMethod, "Method is not public"); } #if NETCF // TODO: Get this to work if (testMethod.Method.IsGenericMethodDefinition) { return MarkAsNotRunnable(testMethod, "Generic test methods are not yet supported under .NET CF"); } #endif ParameterInfo[] parameters = testMethod.Method.GetParameters(); int argsNeeded = parameters.Length; object[] arglist = null; int argsProvided = 0; if (parms != null) { testMethod.parms = parms; testMethod.RunState = parms.RunState; arglist = parms.Arguments; if (arglist != null) argsProvided = arglist.Length; if (testMethod.RunState != RunState.Runnable) return false; } Type returnType = testMethod.Method.ReturnType; if (returnType.Equals(typeof(void))) { if (parms != null && parms.HasExpectedResult) return MarkAsNotRunnable(testMethod, "Method returning void cannot have an expected result"); } else { #if NET_4_5 if (MethodHelper.IsAsyncMethod(testMethod.Method)) { bool returnsGenericTask = returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task<>); if (returnsGenericTask && (parms == null|| !parms.HasExpectedResult && !parms.ExceptionExpected)) return MarkAsNotRunnable(testMethod, "Async test method must have Task or void return type when no result is expected"); else if (!returnsGenericTask && parms != null && parms.HasExpectedResult) return MarkAsNotRunnable(testMethod, "Async test method must have Task<T> return type when a result is expected"); } else #endif if (parms == null || !parms.HasExpectedResult && !parms.ExceptionExpected) return MarkAsNotRunnable(testMethod, "Method has non-void return value, but no result is expected"); } if (argsProvided > 0 && argsNeeded == 0) { return MarkAsNotRunnable(testMethod, "Arguments provided for method not taking any"); } if (argsProvided == 0 && argsNeeded > 0) { return MarkAsNotRunnable(testMethod, "No arguments were provided"); } if (argsProvided != argsNeeded) { return MarkAsNotRunnable(testMethod, "Wrong number of arguments provided"); } #if CLR_2_0 || CLR_4_0 #if !NETCF if (testMethod.Method.IsGenericMethodDefinition) { Type[] typeArguments = GetTypeArgumentsForMethod(testMethod.Method, arglist); foreach (object o in typeArguments) if (o == null) { return MarkAsNotRunnable(testMethod, "Unable to determine type arguments for method"); } testMethod.method = testMethod.Method.MakeGenericMethod(typeArguments); parameters = testMethod.Method.GetParameters(); } #endif #endif if (arglist != null && parameters != null) TypeHelper.ConvertArgumentList(arglist, parameters); return true; }
/// <summary> /// Construct a TestCaseResult based on a TestMethod /// </summary> /// <param name="test">A TestMethod to which the result applies.</param> public TestCaseResult(TestMethod test) : base(test) { }
protected virtual void TestCompleted(TestMethod test) { }
TestCaseElement Setup (TestMethod test) { TestCaseElement tce = new TestCaseElement (test, this); case_elements.Add (test, tce); return tce; }
/// <summary> /// Construct a TestCaseResult based on a TestMethod /// </summary> /// <param name="test">A TestMethod to which the result applies.</param> public TestCaseResult(TestMethod test) : base(test) { }
public override string GetText(TestMethod testMethod, object[] args) { return(testMethod.Id); }