public void TestLoadError() { // A load error is when unittest module fails to load the test (prior to running it) // For example, if the file where the test is defined has an unhandled ImportError. // We check that this only causes the tests that can't be loaded to fail, // all other tests in the test run which can be loaded successfully will be run. var executor = new TestExecutor(); var recorder = new MockTestExecutionRecorder(); var expectedTests = TestInfo.GetTestAdapterLoadErrorTests(ImportErrorFormat); var runContext = CreateRunContext(expectedTests, Version.InterpreterPath); var testCases = expectedTests.Select(tr => tr.TestCase); executor.RunTests(testCases, runContext, recorder); PrintTestResults(recorder); var resultNames = recorder.Results.Select(tr => tr.TestCase.FullyQualifiedName).ToSet(); foreach (var expectedResult in expectedTests) { AssertUtil.ContainsAtLeast(resultNames, expectedResult.TestCase.FullyQualifiedName); var actualResult = recorder.Results.SingleOrDefault(tr => tr.TestCase.FullyQualifiedName == expectedResult.TestCase.FullyQualifiedName); Assert.AreEqual(expectedResult.Outcome, actualResult.Outcome, expectedResult.TestCase.FullyQualifiedName + " had incorrect result"); if (expectedResult.ContainedErrorMessage != null) { Assert.IsNotNull(actualResult.ErrorMessage); Assert.IsTrue( actualResult.ErrorMessage.Contains(expectedResult.ContainedErrorMessage), string.Format("Error message did not contain expected text: {0}", expectedResult.ContainedErrorMessage) ); } else { Assert.IsNull(actualResult.ErrorMessage); } } }
private static void TestLoadError(string projectName) { // A load error is when unittest module fails to load the test (prior to running it) // For example, if the file where the test is defined has an unhandled ImportError. // We check that this only causes the tests that can't be loaded to fail, // all other tests in the test run which can be loaded successfully will be run. var executor = new TestExecutor(); var recorder = new MockTestExecutionRecorder(); var expectedTests = TestInfo.GetTestAdapterLoadErrorTests(projectName); var runContext = CreateRunContext(expectedTests); var testCases = expectedTests.Select(tr => tr.TestCase); executor.RunTests(testCases, runContext, recorder); PrintTestResults(recorder); var resultNames = recorder.Results.Select(tr => tr.TestCase.FullyQualifiedName).ToSet(); foreach (var expectedResult in expectedTests) { AssertUtil.ContainsAtLeast(resultNames, expectedResult.TestCase.FullyQualifiedName); var actualResult = recorder.Results.SingleOrDefault(tr => tr.TestCase.FullyQualifiedName == expectedResult.TestCase.FullyQualifiedName); Assert.AreEqual(expectedResult.Outcome, actualResult.Outcome, expectedResult.TestCase.FullyQualifiedName + " had incorrect result"); } }