コード例 #1
0
        public void NativeAssemblyProducesWarning()
        {
            // Create a fake environment.
            var context       = new FakeRunContext();
            var fakeFramework = new FakeFrameworkHandle();

            // Find the native exaple dll.
            var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "NativeTests.dll");

            Assert.That(File.Exists(path));

            // Try to execute tests from the dll.
            TestAdapterUtils.CreateExecutor().RunTests(
                new[] { path },
                context,
                fakeFramework);

            // Gather results.
            var testResults = fakeFramework.Events
                              .Where(e => e.EventType == FakeFrameworkHandle.EventType.RecordResult)
                              .Select(e => e.TestResult)
                              .ToList();

            // No tests found.
            Assert.That(testResults.Count, Is.EqualTo(0));

            // A warning about unsupported assebly format provided.
            var messages = fakeFramework.Events
                           .Where(e => e.EventType == FakeFrameworkHandle.EventType.SendMessage &&
                                  e.Message.Level == Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestMessageLevel.Warning)
                           .Select(o => o.Message.Text);

            Assert.That(messages, Has.Some.Contains("Assembly not supported"));
        }
コード例 #2
0
        public void TestsWhereShouldFilter(string filter, int expectedCount, int noOfSkipped = 0, int noOfNone = 0)
        {
            // Create a fake environment.
            var context       = new FakeRunContext(new FakeRunSettingsForWhere(filter));
            var fakeFramework = new FakeFrameworkHandle();

            var executor = TestAdapterUtils.CreateExecutor();

            executor.RunTests(new[] { mockAssemblyPath }, context, fakeFramework);

            var completedRuns = fakeFramework.Events.Where(e => e.EventType == FakeFrameworkHandle.EventType.RecordEnd).ToList();

            TestContext.WriteLine(" ");
            foreach (var test in completedRuns)
            {
                TestContext.WriteLine($"{test.TestCase.DisplayName}:{test.TestOutcome}");
            }

            Assert.Multiple(() =>
            {
                Assert.That(completedRuns, Has.Exactly(expectedCount).Items, "Total number wrong");
                Assert.That(completedRuns.Count(o => o.TestOutcome == TestOutcome.Skipped), Is.EqualTo(noOfSkipped), "Skipped number wrong");
                Assert.That(completedRuns.Count(o => o.TestOutcome == TestOutcome.None), Is.EqualTo(noOfNone), "Explicit and inconclusive number wrong");
            });
        }
コード例 #3
0
        public void ThatTestOutputXmlHasBeenCreatedBelowAssemblyFolder()
        {
            var context = new FakeRunContext(new FakeRunSettingsForTestOutput());

            TestAdapterUtils.CreateExecutor().RunTests(new[] { _mockAssemblyPath }, context, testLog);

            var expectedFolder = Path.Combine(_mockAssemblyFolder, "TestResults");

            Assert.That(Directory.Exists(expectedFolder), $"Folder {expectedFolder} not created");
            var expectedFile = Path.Combine(expectedFolder, "mock-assembly.xml");

            Assert.That(File.Exists(expectedFile), $"File {expectedFile} not found");
        }
コード例 #4
0
        public void TestsWhereShouldFilter(string filter, int expectedCount)
        {
            // Create a fake environment.
            var context       = new FakeRunContext(new FakeRunSettingsForWhere(filter));
            var fakeFramework = new FakeFrameworkHandle();

            var executor = TestAdapterUtils.CreateExecutor();

            executor.RunTests(new[] { mockAssemblyPath }, context, fakeFramework);

            var completedRuns = fakeFramework.Events.Where(e => e.EventType == FakeFrameworkHandle.EventType.RecordEnd);

            Assert.That(completedRuns, Has.Exactly(expectedCount).Items);
        }
コード例 #5
0
        public void ThatTestOutputXmlHasBeenAtWorkDirLocation()
        {
            var temp    = Path.GetTempPath();
            var context = new FakeRunContext(new FakeRunSettingsForTestOutputAndWorkDir("TestResult", Path.Combine(temp, "NUnit")));

            var executor = TestAdapterUtils.CreateExecutor();

            executor.RunTests(new[] { _mockAssemblyPath }, context, testLog);
            var expectedFolder = Path.Combine(Path.GetTempPath(), "NUnit", "TestResult");

            Assert.That(Directory.Exists(expectedFolder), $"Folder {expectedFolder} not created");
            var expectedFile = Path.Combine(expectedFolder, "mock-assembly.xml");

            Assert.That(File.Exists(expectedFile), $"File {expectedFile} not found");
        }