Ejemplo n.º 1
0
 public void CanApplyIgnoreAttributeToTestClass()
 {
     TestSuite suite = new TestSuite(typeof(TestClassWithIgnoreAttribute));
     Assert.That(suite, Is.Not.Null);
     Assert.That(suite.RunState, Is.EqualTo(RunState.Ignored));
     Assert.That(suite.IgnoreReason, Is.EqualTo("The Reason"));
 }
 public void TestFailsWhenDerivedExceptionIsThrown()
 {
     TestSuite suite = new TestSuite(typeof(DerivedExceptionThrownClass));
     TestResult result = (TestResult)suite.Run().Results[0];
     Assert.That(result.ResultState, Is.EqualTo(ResultState.Failure));
     Assert.That(result.Message, Is.EqualTo("Expected Exception of type <System.Exception>, but was <System.ApplicationException>"));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads a type as a test using either the test suite
        /// mechansm or the fixture mechanism.
        /// </summary>
        /// <param name="type">The type to be loaded</param>
        /// <returns>A test constructed on that type</returns>
        public static ITest Load(Type type)
        {
            ITest test = TestLoader.LoadAsSuite(type);
            if (test == null)
                test = new TestSuite(type);

            return test;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads a test suite containing multiple tests from an assembly
        /// </summary>
        /// <param name="tests">String array containing the names of the test classes to load</param>
        /// <returns>A suite containing all the tests</returns>
        public static ITest Load(Assembly assembly, string[] tests)
        {
            TestSuite suite = new TestSuite("Test Fixtures");
            foreach (string name in tests)
                suite.AddTest(TestLoader.Load(assembly, name));

            return suite;
        }
        public void Setup()
        {
            TestSuiteBuilder builder = new TestSuiteBuilder();
            TestPackage package = new TestPackage(AssemblyHelper.GetAssemblyPath(typeof(ActionAttributeExceptionFixture)));
            package.TestName = typeof(ActionAttributeExceptionFixture).Namespace;

            _Suite = builder.Build(package);
        }
Ejemplo n.º 6
0
		public void SetUp()
		{
			mockTestFixture = TestBuilder.MakeFixture( typeof( MockTestFixture ) );
			TestSuite noTestFixture = TestBuilder.MakeFixture( typeof( EmptyFixture ) );

			noTestSuite = new TestSuite("No Tests");
			noTestSuite.Add( noTestFixture);
		}
Ejemplo n.º 7
0
		public void SetUp()
		{
			testSuite = new TestSuite("MyTestSuite");
			testFixture = TestBuilder.MakeFixture( typeof( MockTestFixture ) );
			testSuite.Add( testFixture );

			testCase1 = (Test)testFixture.Tests[0];
		}
 public void TestFailsWhenNoExceptionIsThrown()
 {
     TestSuite suite = new TestSuite(typeof(NoExceptionThrownClass));
     TestResult result = (TestResult)suite.Run().Results[0];
     Assert.That(result.ResultState, Is.EqualTo(ResultState.Failure));
     Assert.That(result.Message, Is.EqualTo( 
         "Expected Exception of type <System.ArgumentException>, but none was thrown" ));
 }
Ejemplo n.º 9
0
 public void CanApplyDescriptionToTestMethod()
 {
     TestSuite suite = new TestSuite(typeof(TestClassWithDescription));
     Assert.That(suite, Is.Not.Null);
     Assert.That(suite.TestCaseCount == 1);
     ITest test = (ITest)suite.Tests[0];
     Assert.That(test.Properties["Description"], Is.EqualTo("Method Description"));
 }
		public void FixtureDescriptionInResult()
		{
			TestSuite suite = new TestSuite("Mock Fixture");
			suite.Add( TestBuilder.MakeFixture( typeof( MockFixture ) ) );
            TestResult result = suite.Run(NullListener.NULL, TestFilter.Empty);

		    TestResult fixtureResult = TestFinder.Find("MockFixture", result, true);
            Assert.AreEqual("Fixture Description", fixtureResult.Description);
		}
Ejemplo n.º 11
0
		/// <exception cref="System.Exception"></exception>
		public static TestSuite Suite()
		{
			TestSuite suite = new TestSuite("InteroperableJS tests");
			Uri url = typeof(ComplianceTest).GetResource("1.0");
			string path = URLDecoder.Decode(url.GetFile(), Runtime.GetProperty("file.encoding"));
			FilePath testsDir = new FilePath(path);
			AddTests(suite, testsDir, string.Empty);
			return suite;
		}
Ejemplo n.º 12
0
        public void FixtureDescriptionInResult()
        {
            TestSuite suite = new TestSuite("Mock Fixture");
            suite.Add( TestBuilder.MakeFixture( typeof( MockFixture ) ) );
            TestResult result = suite.Run(NullListener.NULL);

            DescriptionVisitor visitor = new DescriptionVisitor("MockFixture", "Fixture Description");
            result.Accept(visitor);
        }
 public void testNonTestCaseSuitesRecognizeMethodsWithTestAttribute()
 {
     TestSuite suite = new TestSuite(typeof(NonTestCaseClassWithTestAttributes));
     Assert.That(suite.TestCaseCount, Is.EqualTo(3));
     RecordingTestListener listener = new RecordingTestListener();
     suite.Run(listener);
     Assert.That(listener.Events, Is.EqualTo(
         "<NonTestCaseClassWithTestAttributes:<FirstTest::Success><SecondTest::Success><TestThree::Success>:Success>"));
 }
Ejemplo n.º 14
0
 public void CanApplyIgnoreAttributeToTestMethod()
 {
     TestSuite suite = new TestSuite(typeof(TestClassWithIgnoreAttribute));
     Assert.That(suite, Is.Not.Null);
     Assert.That(suite.TestCaseCount == 1);
     ITest test = (ITest)suite.Tests[0];
     Assert.That(test.RunState, Is.EqualTo(RunState.Ignored));
     Assert.That(test.IgnoreReason, Is.EqualTo("NYI"));
 }
		public void FixtureDescription()
		{
			TestSuite suite = new TestSuite("suite");
			suite.Add( TestBuilder.MakeFixture( typeof( MockFixture ) ) );

			IList tests = suite.Tests;
			TestSuite mockFixtureSuite = (TestSuite)tests[0];

			Assert.AreEqual("Fixture Description", mockFixtureSuite.Description);
		}
Ejemplo n.º 16
0
 private TestSuite CreateSimpleSuite(string name)
 {
     TestSuite suite = new TestSuite(name);
     Assert.That( suite.TestCaseCount, Is.EqualTo( 0 ) );
     suite.AddTest( new TestCase( "One", new SimpleTestCase()));
     suite.AddTest( new TestCase( "Two", new SimpleTestCase() ) );
     suite.AddTest( new TestCase( "Three", new SimpleTestCase() ) );
     Assert.That( suite.TestCaseCount, Is.EqualTo( 3 ) );
     return suite;
 }
 public void testInvalidConstructorGivesErrorMessage()
 {
     TestSuite suite = new TestSuite(typeof(ClassWithNoValidConstructor));
     Assert.That( suite.RunState, Is.EqualTo( RunState.NotRunnable ) );
     Assert.That(suite.IgnoreReason, Contains.Substring("no default constructor"));
     Assert.That(suite.TestCaseCount, Is.EqualTo(0) );
     TestResult result = suite.Run();
     Assert.That(result.ResultState, Is.EqualTo(ResultState.Error ));
     Assert.That(result.Message, Is.EqualTo( suite.IgnoreReason ));
 }
Ejemplo n.º 18
0
 public void IgnoreTestFixture()
 {
     TestSuite suite = new TestSuite(typeof(IgnoredTestFixture));
     Assert.That(suite, Is.Not.Null);
     Assert.That(suite.TestCaseCount, Is.EqualTo(2));
     Assert.That(suite.RunState, Is.EqualTo(RunState.Ignored));
     TestResult result = suite.Run();
     Assert.That(result.ResultState, Is.EqualTo( ResultState.NotRun ) );
     Assert.That(result.Message, Is.EqualTo("Ignore all the tests"));
     Assert.That(result.Results.Count, Is.EqualTo(0));
 }
Ejemplo n.º 19
0
 public void IgnoreTestCase()
 {
     TestSuite suite = new TestSuite(typeof(FixtureWithIgnoredTestCase));
     Assert.That(suite, Is.Not.Null);
     Assert.That(suite.TestCaseCount, Is.EqualTo(1));
     TestResult result = suite.Run();
     Assert.That(result.IsSuccess);
     Assert.That(result.Results.Count, Is.EqualTo(1));
     TestResult caseResult = (TestResult)result.Results[0];
     Assert.That(caseResult.ResultState, Is.EqualTo(ResultState.NotRun));
     Assert.That(caseResult.Message, Is.EqualTo("I ignored this"));
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Loads all the test fixtures in an assembly
        /// </summary>
        /// <param name="assembly">The assembly to be loaded</param>
        /// <returns>A Test containing all fixtures found</returns>
        public static ITest Load(Assembly assembly)
        {
            TestSuite suite = new TestSuite(assembly.GetName().Name);

            foreach (Type type in assembly.GetTypes())
            {
                if (IsTestFixture(type))
                    suite.AddTest(new TestSuite(type));
            }

            return suite;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Loads all the test fixtures in an assembly
        /// </summary>
        /// <param name="assembly">The assembly to be loaded</param>
        /// <returns>A Test containing all fixtures found</returns>
        public static ITest Load(Assembly assembly)
        {
            TestSuite suite = new TestSuite(assembly.GetName().Name);

            foreach (Type type in assembly.GetTypes())
            {
                if ( Reflect.HasAttribute( type, typeof(TestFixtureAttribute) ) )
                    suite.AddTest(new TestSuite(type));
            }

            return suite;
        }
        public void DescriptionInResult()
        {
            TestSuite suite = new TestSuite("Mock Fixture");
            suite.Add(TestBuilder.MakeFixture(typeof(MockFixture)));
            TestResult result = suite.Run(NullListener.NULL, TestFilter.Empty);

            TestResult caseResult = TestFinder.Find("Method", result, true);
            Assert.AreEqual("Test Description", caseResult.Description);

            caseResult = TestFinder.Find("NoDescriptionMethod", result, true);
            Assert.IsNull(caseResult.Description);
        }
Ejemplo n.º 23
0
		private static void AddCategories(TestSuite suite, FilePath suiteDir, string prefix, string[] excludes, int optimizationLevel)
		{
			FilePath[] subdirs = suiteDir.ListFiles(ShellTest.DIRECTORY_FILTER);
			Arrays.Sort(subdirs);
			for (int i = 0; i < subdirs.Length; i++)
			{
				FilePath subdir = subdirs[i];
				string name = subdir.GetName();
				TestSuite testCategory = new TestSuite(name);
				AddTests(testCategory, subdir, prefix + name + "/", excludes, optimizationLevel);
				suite.AddTest(testCategory);
			}
		}
Ejemplo n.º 24
0
		public void IgnoreWorksForTestSuite()
		{
			//IgnoredTestSuiteFixture testFixture = new IgnoredTestSuiteFixture();
			TestSuite suite = new TestSuite("IgnoredTestFixture");
			suite.Add( TestBuilder.MakeFixture( typeof( IgnoredTestSuiteFixture ) ) );
            TestResult result = suite.Run(NullListener.NULL, TestFilter.Empty);

			TestResult fixtureResult = (TestResult)result.Results[0];
			Assert.IsFalse( fixtureResult.Executed, "Fixture should not have been executed" );
			
			foreach( TestResult testResult in fixtureResult.Results )
				Assert.IsFalse( testResult.Executed, "Test case should not have been executed" );
		}
Ejemplo n.º 25
0
        public void DescriptionInResult()
        {
            TestSuite suite = new TestSuite("Mock Fixture");
            suite.Add(TestBuilder.MakeFixture(typeof(MockFixture)));
            TestResult result = suite.Run(NullListener.NULL);

            DescriptionVisitor visitor = new DescriptionVisitor("NUnit.Tests.Attributes.MockFixture.Method", "Test Description");
            result.Accept(visitor);

            visitor =
                new DescriptionVisitor("NUnit.Tests.Attributes.MockFixture.NoDescriptionMethod", null);
            result.Accept(visitor);
        }
 public void testCanCreateSuiteAutomaticallyFromClass()
 {
     TestSuite suite = new TestSuite(typeof(SimpleTestCase));
     Assert.That(suite.TestCaseCount, Is.EqualTo(6));
     foreach (ITest test in suite.Tests)
         Assert.That(test, Is.InstanceOfType(typeof(SimpleTestCase)) | Is.InstanceOfType(typeof(InvalidTestCase)), "Not a TestCase");
     RecordingTestListener listener = new RecordingTestListener();
     TestResult result = suite.Run(listener);
     Assert.That(result.ResultState, Is.EqualTo(ResultState.Failure));
     Assert.That(result.Results.Count, Is.EqualTo(6));
     Assert.That(listener.Events, Is.EqualTo(
         "<SimpleTestCase:<test1::Success><test2::Success><Test3::Success><TEST4::Success><test6::Failure><test7::Failure>:Failure>"));
 }
Ejemplo n.º 27
0
		private static void AddTests(TestSuite suite, FilePath suiteDir, string prefix, string[] excludes, int optimizationLevel)
		{
			FilePath[] jsFiles = suiteDir.ListFiles(ShellTest.TEST_FILTER);
			Arrays.Sort(jsFiles);
			for (int i = 0; i < jsFiles.Length; i++)
			{
				FilePath jsFile = jsFiles[i];
				string name = jsFile.GetName();
				if (!TestUtils.Matches(excludes, prefix + name))
				{
					suite.AddTest(new StandardTests.JsTestCase(jsFile, optimizationLevel));
				}
			}
		}
Ejemplo n.º 28
0
		private static void AddSuites(TestSuite topLevel, FilePath testDir, string[] excludes, int optimizationLevel)
		{
			FilePath[] subdirs = testDir.ListFiles(ShellTest.DIRECTORY_FILTER);
			Arrays.Sort(subdirs);
			for (int i = 0; i < subdirs.Length; i++)
			{
				FilePath subdir = subdirs[i];
				string name = subdir.GetName();
				if (TestUtils.Matches(excludes, name))
				{
					continue;
				}
				TestSuite testSuite = new TestSuite(name);
				AddCategories(testSuite, subdir, name + "/", excludes, optimizationLevel);
				topLevel.AddTest(testSuite);
			}
		}
Ejemplo n.º 29
0
		private static void AddTests(TestSuite suite, FilePath testDir, string name)
		{
			FilePath programFile = new FilePath(testDir, "program.js");
			if (programFile.IsFile())
			{
				suite.AddTest(CreateTest(testDir, name));
			}
			else
			{
				FilePath[] files = testDir.ListFiles();
				foreach (FilePath file in files)
				{
					if (file.IsDirectory())
					{
						AddTests(suite, file, name + "/" + file.GetName());
					}
				}
			}
		}
		public void IgnoredFixtureShouldNotCallFixtureSetUpOrTearDown()
		{
			IgnoredFixture fixture = new IgnoredFixture();
			TestSuite suite = new TestSuite("IgnoredFixtureSuite");
			TestSuite fixtureSuite = TestBuilder.MakeFixture( fixture.GetType() );
			suite.Fixture = fixture;
			Test test = (Test)fixtureSuite.Tests[0];
			suite.Add( fixtureSuite );

            fixtureSuite.Run(NullListener.NULL, TestFilter.Empty);
			Assert.IsFalse( fixture.setupCalled, "TestFixtureSetUp called running fixture" );
			Assert.IsFalse( fixture.teardownCalled, "TestFixtureTearDown called running fixture" );

            suite.Run(NullListener.NULL, TestFilter.Empty);
			Assert.IsFalse( fixture.setupCalled, "TestFixtureSetUp called running enclosing suite" );
			Assert.IsFalse( fixture.teardownCalled, "TestFixtureTearDown called running enclosing suite" );

            test.Run(NullListener.NULL, TestFilter.Empty);
			Assert.IsFalse( fixture.setupCalled, "TestFixtureSetUp called running a test case" );
			Assert.IsFalse( fixture.teardownCalled, "TestFixtureTearDown called running a test case" );
		}