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")); }
public void WhenAssemblyIsNative() { var context = new FakeDiscoveryContext(null); var messageLoggerStub = new MessageLoggerStub(); var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "NativeTests.dll"); Assert.That(File.Exists(path)); TestAdapterUtils.CreateDiscoverer().DiscoverTests( new[] { path }, context, messageLoggerStub, this); Assert.Multiple(() => { Assert.That(testcaseWasSent, Is.False); Assert.That(messageLoggerStub.WarningMessages.Count(), Is.EqualTo(1)); Assert.That(!messageLoggerStub.ErrorMessages.Any()); string warningmsg = messageLoggerStub.WarningMessages.Select(o => o.Item2).FirstOrDefault(); Assert.That(warningmsg, Is.Not.Null); if (!string.IsNullOrEmpty(warningmsg)) { Assert.That(warningmsg, Does.Contain("Assembly not supported")); } }); }
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"); }); }
public void VerifyLoading(IDiscoveryContext context) { // Load the NUnit empty-assembly.dll once for this test TestAdapterUtils.CreateDiscoverer().DiscoverTests( new[] { EmptyAssemblyPath }, context, new MessageLoggerStub(), this); }
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"); }
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); }
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"); }
public void LoadMockassembly() { // Sanity check to be sure we have the correct version of mock-assembly.dll Assert.That(NUnit.Tests.Assemblies.MockAssembly.TestsAtRuntime, Is.EqualTo(NUnit.Tests.Assemblies.MockAssembly.Tests), "The reference to mock-assembly.dll appears to be the wrong version"); Assert.That(File.Exists(MockAssemblyPath), $"Can't locate mock-assembly.dll at {MockAssemblyPath}"); testCases = new List <TestCase>(); // Load the NUnit mock-assembly.dll once for this test, saving // the list of test cases sent to the discovery sink TestAdapterUtils.CreateDiscoverer().DiscoverTests( new[] { MockAssemblyPath }, _context, new MessageLoggerStub(), this); }
public void WhenAssemblyDontExist() { int noOfMessagesFound = 3; // Start + end, + info var context = new FakeDiscoveryContext(null); var messageLoggerStub = new MessageLoggerStub(); TestAdapterUtils.CreateDiscoverer().DiscoverTests( new[] { "FileThatDoesntExist.dll" }, context, messageLoggerStub, this); Assert.That(messageLoggerStub.Count, Is.EqualTo(noOfMessagesFound)); Assert.That(messageLoggerStub.LatestTestMessageLevel, Is.EqualTo(TestMessageLevel.Informational)); Assert.That(testcaseWasSent, Is.False); Assert.That(!messageLoggerStub.ErrorMessages.Any()); }
public void LoadMockassembly() { mockAssemblyPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "mock-assembly.dll"); // Sanity check to be sure we have the correct version of mock-assembly.dll Assert.That(MockAssembly.TestsAtRuntime, Is.EqualTo(MockAssembly.Tests), "The reference to mock-assembly.dll appears to be the wrong version"); testLog = new FakeFrameworkHandle(); // Load the NUnit mock-assembly.dll once for this test, saving // the list of test cases sent to the discovery sink TestAdapterUtils.CreateExecutor().RunTests(new[] { mockAssemblyPath }, Context, testLog); var testResults = testLog.Events .Where(e => e.EventType == FakeFrameworkHandle.EventType.RecordResult) .Select(e => e.TestResult) .ToList(); this.Summary = new ResultSummary(testResults); }
public void LoadMockassembly() { // Sanity check to be sure we have the correct version of mock-assembly.dll. Assert.That(NUnit.Tests.Assemblies.MockAssembly.TestsAtRuntime, Is.EqualTo(NUnit.Tests.Assemblies.MockAssembly.Tests), "The reference to mock-assembly.dll appears to be the wrong version"); Assert.That(File.Exists(MockAssemblyPath), $"Can't locate mock-assembly.dll at {MockAssemblyPath}"); var runsettings = "<RunSettings><NUnit><UseParentFQNForParametrizedTests>True</UseParentFQNForParametrizedTests><SkipNonTestAssemblies>false</SkipNonTestAssemblies><DiscoveryMethod>Legacy</DiscoveryMethod></NUnit></RunSettings>"; var rs = Substitute.For <IRunSettings>(); rs.SettingsXml.Returns(runsettings); _context.RunSettings.Returns(rs); // Load the NUnit mock-assembly.dll once for this test, saving // the list of test cases sent to the discovery sink. var discoverer = TestAdapterUtils.CreateDiscoverer(); discoverer.DiscoverTests( new[] { MockAssemblyPath }, _context, new MessageLoggerStub(), this); }