public static void Main(string[] args) { var errors = SolutionValidations.ValidateSolution(); if (errors.Count != 0) { var serialized = string.Join("\r\n", errors); throw new Exception($"В задании были найдены ошибки. Их нужно исправить:\r\n{serialized}"); } var testRunner = TestRunningHelpers.CreateTestRunner(); if (!TestsAreValid(testRunner)) { return; } var implementationStatuses = RunIncorrectImplementationsTests(testRunner); new TestRunReport(implementationStatuses, ShouldPrintDebugInfo).WriteToConsole(); try { AllBugsReport.WriteAllBugsToFile(AllBugsReportPath); } catch (Exception) { //При запуске в юлерне напечатать не получится, потому что там нельзя. Ну и ладно. } }
public void GetFailedTestsTest() { var failedTests = TestRunningHelpers.GetFailedTests(testRunner, typeof(DummyTests)).ToList(); Assert.AreEqual(2, failedTests.Count); var firstFailedTest = failedTests.Single(x => x.Name == "TestWhichFails1"); Assert.AreEqual("Все ок, он и должен падать.", firstFailedTest.FailMessage); var secondFailedTest = failedTests.Single(x => x.Name == "TestWhichFails2"); Assert.AreEqual("Все ок, он и должен падать.", secondFailedTest.FailMessage); }
private static bool TestsAreValid(ITestAssemblyRunner testRunner) { Console.WriteLine("Проверяем, что все тесты проходят на эталонной CoffeeMachine..."); var failed = TestRunningHelpers.GetFailedTests(testRunner, typeof(CoffeeMachineTestsTask)).ToList(); if (failed.Any()) { Console.WriteLine( "Тесты не в порядке. На эталонной CoffeeMachine не прошли: " + string.Join(", ", failed.Select(x => x.ToString(ShouldPrintDebugInfo)))); return(false); } Console.WriteLine("Тесты в порядке."); return(true); }
private static IEnumerable <ImplementationStatus> GetIncorrectImplementationsResults( ITestAssemblyRunner testRunner, IEnumerable <Type> implementations) { var implTypeToTestsType = AssemblyHelper.GetIncorrectImplementationTests() .ToDictionary(t => { t.SetUp(); return(t.CoffeeMachine.GetType()); }, t => t.GetType()); foreach (var implementation in implementations) { var isSecret = implementation.HasAttribute <SecretAttribute>(); var failed = TestRunningHelpers.GetFailedTests(testRunner, implTypeToTestsType[implementation]) .ToArray(); yield return(new ImplementationStatus( implementation.Name, failed, IncorrectImplementationAttribute.GetDescription(implementation), isSecret)); } }