protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); test_suite = Intent.GetStringExtra ("TestSuite"); suite = AndroidRunner.Suites [test_suite]; var menu = new RootElement (String.Empty); while (suite.Tests.Count == 1 && (suite.Tests[0] is TestSuite)) suite = (TestSuite)suite.Tests[0]; main = new Section(suite.FullName ?? suite.Name); foreach (ITest test in suite.Tests) { TestSuite ts = test as TestSuite; if (ts != null) main.Add (new TestSuiteElement (ts)); else main.Add (new TestCaseElement (test)); } menu.Add (main); Section options = new Section () { new ActionElement ("Run all", Run), }; menu.Add (options); var da = new DialogAdapter (this, menu); var lv = new ListView (this) { Adapter = da }; SetContentView (lv); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); test_suite = Intent.GetStringExtra ("TestSuite"); if (!AndroidRunner.Suites.TryGetValue(test_suite, out suite)) { suite = null; } var menu = new RootElement (String.Empty); main = new Section (test_suite); if (suite != null) { foreach (ITest test in suite.Tests) { TestSuite ts = test as TestSuite; if (ts != null) main.Add(new TestSuiteElement(ts, AndroidRunner.Runner)); else main.Add(new TestCaseElement(test as TestMethod, AndroidRunner.Runner)); } } menu.Add (main); Section options = new Section () { new ActionElement ("Run all", Run), }; menu.Add (options); var da = new DialogAdapter (this, menu); var lv = new ListView (this) { Adapter = da }; SetContentView (lv); }
/// <summary> /// Loads the tests found in an Assembly /// </summary> /// <param name="assembly">The assembly to load</param> /// <param name="settings">Dictionary of option settings for loading the assembly</param> /// <returns>True if the load was successful</returns> public bool Load(Assembly assembly, IDictionary settings) { this.settings = settings; this.loadedTest = this.builder.Build(assembly, settings); if (loadedTest == null) return false; return true; }
public void FixtureAuthor() { var suite = new TestSuite("suite"); suite.Add(TestBuilder.MakeFixture(FixtureType)); var mockFixtureSuite = (TestSuite)suite.Tests[0]; Assert.AreEqual("Rob Prouse", mockFixtureSuite.Properties.Get(PropertyNames.Author)); }
public void FixtureTestOf() { var suite = new TestSuite("suite"); suite.Add(TestBuilder.MakeFixture(FixtureType)); var mockFixtureSuite = (TestSuite)suite.Tests[0]; Assert.AreEqual("NUnit.Framework.TestOfAttribute", mockFixtureSuite.Properties.Get(PropertyNames.TestOf)); }
public void FixtureDescription() { TestSuite suite = new TestSuite("suite"); suite.Add( TestBuilder.MakeFixture( typeof( DescriptionFixture ) ) ); TestSuite mockFixtureSuite = (TestSuite)suite.Tests[0]; Assert.AreEqual("Fixture Description", mockFixtureSuite.Properties.Get(PropertyNames.Description)); }
public void IgnoreWorksForTestSuite() { TestSuite suite = new TestSuite("IgnoredTestFixture"); suite.Add( TestBuilder.MakeFixture( typeof( IgnoredTestSuiteFixture ) ) ); ITestResult fixtureResult = TestBuilder.RunTestSuite(suite, null).Children[0]; Assert.AreEqual(ResultState.Ignored, fixtureResult.ResultState); foreach (ITestResult testResult in fixtureResult.Children) Assert.AreEqual(ResultState.Ignored, testResult.ResultState); }
public void IgnoreWorksForTestSuite() { TestSuite suite = new TestSuite("IgnoredTestFixture"); suite.Add( TestBuilder.MakeFixture( typeof( IgnoredTestSuiteFixture ) ) ); ITestResult fixtureResult = TestBuilder.RunTest(suite).Children.ToArray ()[0]; Assert.AreEqual(ResultState.Ignored.WithSite(FailureSite.SetUp), fixtureResult.ResultState); foreach (ITestResult testResult in fixtureResult.Children) Assert.AreEqual(ResultState.Ignored.WithSite(FailureSite.Parent), testResult.ResultState); }
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 TestSuiteElement (TestSuite test, TouchRunner runner) : base (test, runner) { Caption = Suite.Name; int count = Suite.TestCaseCount; if (count > 0) { Accessory = UITableViewCellAccessory.DisclosureIndicator; DetailColor = DarkGreen; Value = String.Format ("{0} test case{1}, {2}", count, count == 1 ? String.Empty : "s", Suite.RunState); Tapped += delegate { runner.Show (Suite); }; } else { DetailColor = UIColor.Orange; Value = "No test was found inside this suite"; } }
public static TestSuite GroupByNamespace(TestSuite testSuite) { if (testSuite == null) return null; var result = new TestSuite(testSuite.Name + ".Application"); foreach (var testGroup in testSuite.Tests.GroupBy(x => GetNamespace(x))) { var namespaceSuite = new TestNamespace(testGroup.Key); foreach (var test in testGroup) { namespaceSuite.Tests.Add(test); } result.Tests.Add(namespaceSuite); } return result; }
public static Test Find(string name, TestSuite suite, bool recursive) { foreach (Test child in suite.Tests) { if (child.Name == name) return child; if (recursive) { TestSuite childSuite = child as TestSuite; if (childSuite != null) { Test grandchild = Find(name, childSuite, true); if (grandchild != null) return grandchild; } } } return null; }
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(); }
internal static void Run(string title, Stream outputStream) { var suite = new TestSuite(title); var builder = new NUnitLiteTestAssemblyBuilder(); suite.Add(builder.Build(System.Reflection.Assembly.GetExecutingAssembly(), new Dictionary<string, object>())); var testExecutionContext = TestExecutionContext.CurrentContext; testExecutionContext.WorkDirectory = Environment.CurrentDirectory; #if __IOS__ var workItem = suite.CreateWorkItem(TestFilter.Empty, new FinallyDelegate()); #else var workItem = suite.CreateWorkItem(TestFilter.Empty); #endif workItem.Execute(testExecutionContext); var testWriter = new NUnitLite.Runner.NUnit2XmlOutputWriter(DateTime.Now); using (var writer = new StreamWriter(outputStream)) { testWriter.WriteResultFile(workItem.Result, writer); } }
void Add (TestSuite suite) { var name = suite.FullName ?? suite.Name; if (!AndroidRunner.Suites.ContainsKey(name)) { AndroidRunner.Suites.Add(suite.FullName ?? suite.Name, suite); } foreach (ITest test in suite.Tests) { TestSuite ts = (test as TestSuite); if (ts != null) Add (ts); } }
/// <summary> /// Method to create a test case from a MethodInfo and add /// it to the fixture being built. It first checks to see if /// any global TestCaseBuilder addin wants to build the /// test case. If not, it uses the internal builder /// collection maintained by this fixture builder. After /// building the test case, it applies any decorators /// that have been installed. /// /// The default implementation has no test case builders. /// Derived classes should add builders to the collection /// in their constructor. /// </summary> /// <param name="method">The MethodInfo for which a test is to be created</param> /// <param name="suite">The test suite being built.</param> /// <returns>A newly constructed Test</returns> private Test BuildTestCase( MethodInfo method, TestSuite suite ) { return testBuilder.CanBuildFrom(method, suite) ? testBuilder.BuildFrom(method, suite) : null; }
public TestSuiteResult(TestSuite suite) : base(suite) { }
bool AddSuite (TestSuite ts) { if (ts == null) return false; suite.Add (ts); return true; }
TestSuiteElement Setup (TestSuite suite) { while (suite.Tests.Count == 1 && (suite.Tests[0] is TestSuite)) suite = (TestSuite)suite.Tests[0]; TestSuiteElement tse = new TestSuiteElement (suite, this); suite_elements.Add (suite, tse); var root = new RootElement ("Tests"); Section section = new Section (suite.Name); foreach (ITest test in suite.Tests) { TestSuite ts = (test as TestSuite); if (ts != null) { section.Add (Setup (ts)); } else { TestMethod tc = (test as TestMethod); if (tc != null) { section.Add (Setup (tc)); } else { throw new NotImplementedException (test.GetType ().ToString ()); } } } root.Add (section); if (section.Count > 1) { Section options = new Section () { new StringElement ("Run all", async delegate () { if (OpenWriter (suite.Name)) { await Run (suite); CloseWriter (); suites_dvc [suite].Filter (); } }) }; root.Add (options); } suites_dvc.Add (suite, new TouchViewController (root)); return tse; }
public void Show (TestSuite suite) { NavigationController.PushViewController (suites_dvc [suite], true); }
public void CreateFixture() { fixture = TestBuilder.MakeFixture( typeof( FixtureWithCategories ) ); }
public void IgnoredFixtureShouldNotCallFixtureSetUpOrTearDown() { IgnoredFixture fixture = new IgnoredFixture(); TestSuite suite = new TestSuite("IgnoredFixtureSuite"); TestSuite fixtureSuite = TestBuilder.MakeFixture( fixture.GetType() ); TestMethod testMethod = (TestMethod)fixtureSuite.Tests[0]; suite.Add( fixtureSuite ); TestBuilder.RunTestSuite(fixtureSuite, fixture); Assert.IsFalse( fixture.setupCalled, "TestFixtureSetUp called running fixture" ); Assert.IsFalse( fixture.teardownCalled, "TestFixtureTearDown called running fixture" ); TestBuilder.RunTestSuite(suite, fixture); Assert.IsFalse( fixture.setupCalled, "TestFixtureSetUp called running enclosing suite" ); Assert.IsFalse( fixture.teardownCalled, "TestFixtureTearDown called running enclosing suite" ); TestBuilder.RunTest(testMethod, fixture); Assert.IsFalse( fixture.setupCalled, "TestFixtureSetUp called running a test case" ); Assert.IsFalse( fixture.teardownCalled, "TestFixtureTearDown called running a test case" ); }
void Add (TestSuite suite) { var suiteName = suite.FullName ?? suite.Name; // add a suffix to the name if a test with the same name already exists var count = 2; while (AndroidRunner.Suites.ContainsKey(suiteName)) { suiteName = (suite.FullName ?? suite.Name) + count; ++count; } suite.FullName = suite.Name = suiteName; AndroidRunner.Suites.Add(suiteName, suite); foreach (ITest test in suite.Tests) { TestSuite ts = (test as TestSuite); if (ts != null) Add (ts); } }
private void CheckXmlForTest(Test test, XmlNode topNode, bool recursive) { Assert.NotNull(topNode); //if (test is TestSuite) //{ // Assert.That(topNode.Name, Is.EqualTo("test-suite")); // Assert.That(topNode.Attributes["type"].Value, Is.EqualTo(test.XmlElementName)); //} //else //{ // Assert.That(topNode.Name, Is.EqualTo("test-case")); //} Assert.That(topNode.Name, Is.EqualTo(test.XmlElementName)); Assert.That(topNode.Attributes["id"], Is.EqualTo(test.Id.ToString())); Assert.That(topNode.Attributes["name"], Is.EqualTo(test.Name)); Assert.That(topNode.Attributes["fullname"], Is.EqualTo(test.FullName)); int expectedCount = test.Properties.Count; if (expectedCount > 0) { string[] expectedProps = new string[expectedCount]; int count = 0; foreach (PropertyEntry entry in test.Properties) { expectedProps[count++] = entry.ToString(); } XmlNode propsNode = topNode.FindDescendant("properties"); Assert.NotNull(propsNode); int actualCount = propsNode.ChildNodes.Count; string[] actualProps = new string[actualCount]; for (int i = 0; i < actualCount; i++) { XmlNode node = propsNode.ChildNodes[i] as XmlNode; string name = node.Attributes["name"]; string value = node.Attributes["value"]; actualProps[i] = name + "=" + value.ToString(); } Assert.That(actualProps, Is.EquivalentTo(expectedProps)); } if (recursive) { TestSuite suite = test as TestSuite; if (suite != null) { foreach (Test child in suite.Tests) { string xpathQuery = string.Format("{0}[@id={1}]", child.XmlElementName, child.Id); XmlNode childNode = topNode.FindDescendant(xpathQuery); Assert.NotNull(childNode, "Expected node for test with ID={0}, Name={1}", child.Id, child.Name); CheckXmlForTest(child, childNode, recursive); } } } }
public void TestFixtureMultipleAuthors() { var suite = new TestSuite("suite"); suite.Add(TestBuilder.MakeFixture(FixtureType)); var mockFixtureSuite = (TestSuite)suite.Tests[0]; Assert.That(mockFixtureSuite.Properties[PropertyNames.Author], Is.EqualTo( new[] { "Rob Prouse", "Charlie Poole <*****@*****.**>", "NUnit" })); }
public TestSuiteElement (TestSuite suite) : base (suite) { if (Suite.TestCaseCount > 0) Indicator = ">"; // hint there's more }
/// <summary> /// Construct a TestSuiteResult base on a TestSuite /// </summary> /// <param name="suite">The TestSuite to which the result applies</param> public TestSuiteResult(TestSuite suite) : base(suite) { }
public UIViewController GetViewController () { var menu = new RootElement ("Test Runner"); var runMode = new Section("Run Mode"); var interactiveCheckBox = new CheckboxElement("Enable Interactive Mode"); interactiveCheckBox.Tapped += () => GraphicsTestBase.ForceInteractiveMode = interactiveCheckBox.Value; runMode.Add(interactiveCheckBox); menu.Add(runMode); Section main = new Section ("Loading test suites..."); menu.Add (main); Section options = new Section () { new StyledStringElement ("Options", Options) { Accessory = UITableViewCellAccessory.DisclosureIndicator }, new StyledStringElement ("Credits", Credits) { Accessory = UITableViewCellAccessory.DisclosureIndicator } }; menu.Add (options); // large unit tests applications can take more time to initialize // than what the iOS watchdog will allow them on devices ThreadPool.QueueUserWorkItem (delegate { foreach (Assembly assembly in assemblies) Load (assembly, null); window.InvokeOnMainThread (delegate { while (suite.Tests.Count == 1 && (suite.Tests[0] is TestSuite)) suite = (TestSuite)suite.Tests[0]; foreach (TestSuite ts in suite.Tests) { main.Add (Setup (ts)); } mre.Set (); main.Caption = null; menu.Reload (main, UITableViewRowAnimation.Fade); options.Insert (0, new StringElement ("Run Everything", Run)); menu.Reload (options, UITableViewRowAnimation.Fade); }); assemblies.Clear (); }); var dv = new DialogViewController (menu) { Autorotate = true }; // AutoStart running the tests (with either the supplied 'writer' or the options) if (AutoStart) { ThreadPool.QueueUserWorkItem (delegate { mre.WaitOne (); window.BeginInvokeOnMainThread (delegate { Run (); // optionally end the process, e.g. click "Touch.Unit" -> log tests results, return to springboard... // http://stackoverflow.com/questions/1978695/uiapplication-sharedapplication-terminatewithsuccess-is-not-there if (TerminateAfterExecution) TerminateWithSuccess (); }); }); } return dv; }
/// <summary> /// Loads the tests found in an Assembly /// </summary> /// <param name="assemblyName">File name of the assembly to load</param> /// <param name="settings">Dictionary of option settings for loading the assembly</param> /// <returns>True if the load was successful</returns> public bool Load(string assemblyName, IDictionary settings) { _settings = settings; Randomizer.InitialSeed = settings.Contains("RandomSeed") ? (int)settings["RandomSeed"] : new Random().Next(); _loadedTest = (TestSuite)_builder.Build(assemblyName, settings); if (_loadedTest == null) return false; return true; }
public void CreateFixture() { fixture = TestBuilder.MakeFixture( typeof( FixtureWithProperties ) ); }
/// <summary> /// Construct a TestSuiteResult base on a TestSuite /// </summary> /// <param name="suite">The TestSuite to which the result applies</param> public TestSuiteResult(TestSuite suite) : base(suite) { _children = new List<ITestResult>(); }
/// <summary> /// Loads the tests found in an Assembly /// </summary> /// <param name="assembly">The assembly to load</param> /// <param name="settings">Dictionary of option settings for loading the assembly</param> /// <returns>True if the load was successful</returns> public bool Load(Assembly assembly, IDictionary settings) { _settings = settings; _loadedTest = (TestSuite)_builder.Build(assembly, settings); if (_loadedTest == null) return false; return true; }