Esempio n. 1
0
        public void ExecuteOnlyOnce_WhenRetriestCountSetToTwoAndNoFailedTestsPresent()
        {
            var log = Mock.Create <ILog>();

            Mock.Arrange(() => log.Info(Arg.AnyString));
            var consoleArgumentsProvider = Mock.Create <IConsoleArgumentsProvider>();
            var newFileName = Path.GetTempFileName();

            Mock.Arrange(() => consoleArgumentsProvider.NewTestResultPath).Returns(newFileName);
            Mock.Arrange(() => consoleArgumentsProvider.TestResultPath).Returns("NoExceptions.trx");
            Mock.Arrange(() => consoleArgumentsProvider.ConsoleArguments).Returns("ipconfig");
            Mock.Arrange(() => consoleArgumentsProvider.RetriesCount).Returns(2);
            var processExecutionProvider = Mock.Create <IProcessExecutionProvider>();

            Mock.Arrange(() => processExecutionProvider.ExecuteProcessWithAdditionalArguments(string.Empty)).DoNothing();
            Mock.Arrange(() => processExecutionProvider.CurrentProcessWaitForExit()).DoNothing();
            var fileSystemProvider = Mock.Create <IFileSystemProvider>();

            Mock.Arrange(() => fileSystemProvider.SerializeTestRun(Arg.IsAny <TestRun>())).DoNothing();
            var testRun = new TestRun();
            var testRunUnitTestResult = new TestRunUnitTestResult()
            {
                Outcome = "Passed"
            };

            testRun.Results = new TestRunUnitTestResult[]
            {
                testRunUnitTestResult,
                testRunUnitTestResult
            };
            testRun.ResultSummary         = new TestRunResultSummary();
            testRun.ResultSummary.Outcome = "Passed";
            Mock.Arrange(() => fileSystemProvider.DeserializeTestRun(Arg.AnyString)).Returns(testRun);
            var microsoftTestRunProvider = Mock.Create <IMsTestTestRunProvider>();

            Mock.Arrange(() => microsoftTestRunProvider.GetAllPassesTests(Arg.IsAny <TestRun>())).DoNothing();
            Mock.Arrange(() => microsoftTestRunProvider.UpdatePassedTests(Arg.IsAny <List <TestRunUnitTestResult> >(), Arg.IsAny <List <TestRunUnitTestResult> >())).DoNothing();
            Mock.Arrange(() => microsoftTestRunProvider.UpdateResultsSummary(Arg.IsAny <TestRun>())).DoNothing();
            Mock.Arrange(() => microsoftTestRunProvider.GetAllNotPassedTests(Arg.IsAny <List <TestRunUnitTestResult> >())).Returns(new List <TestRunUnitTestResult>()
            {
            });
            Mock.Arrange(() => microsoftTestRunProvider.GenerateAdditionalArgumentsForFailedTestsRun(Arg.IsAny <List <TestRunUnitTestResult> >(), Arg.AnyString)).DoNothing();

            var engine = new TestExecutionService(
                microsoftTestRunProvider,
                fileSystemProvider,
                processExecutionProvider,
                consoleArgumentsProvider,
                log);
            var result = engine.ExecuteWithRetry();

            Mock.Assert(() => processExecutionProvider.ExecuteProcessWithAdditionalArguments(Arg.AnyString), Occurs.Once());
            Mock.Assert(() => fileSystemProvider.DeserializeTestRun(Arg.AnyString), Occurs.Once());
            Mock.Assert(() => microsoftTestRunProvider.GenerateAdditionalArgumentsForFailedTestsRun(Arg.IsAny <List <TestRunUnitTestResult> >(), Arg.AnyString), Occurs.Never());
            Mock.Assert(() => microsoftTestRunProvider.GetAllPassesTests(Arg.IsAny <TestRun>()), Occurs.Never());
            Mock.Assert(() => microsoftTestRunProvider.UpdatePassedTests(Arg.IsAny <List <TestRunUnitTestResult> >(), Arg.IsAny <List <TestRunUnitTestResult> >()), Occurs.Never());
            Mock.Assert(() => microsoftTestRunProvider.UpdateResultsSummary(Arg.IsAny <TestRun>()), Occurs.Never());
            Mock.Assert(() => fileSystemProvider.SerializeTestRun(Arg.IsAny <TestRun>()), Occurs.Exactly(1));
            Assert.AreEqual <int>(0, result);
        }
        public void ExecuteOnlyOnce_WhenThresholdSmallerThanFailedTestsPercentage()
        {
            var log = Mock.Create <ILog>();

            Mock.Arrange(() => log.Info(Arg.AnyString));
            var    consoleArgumentsProvider = Mock.Create <IConsoleArgumentsProvider>();
            string newFileName = Path.GetTempFileName();

            Mock.Arrange(() => consoleArgumentsProvider.NewTestResultPath).Returns(newFileName);
            Mock.Arrange(() => consoleArgumentsProvider.TestResultPath).Returns("Exceptions.trx");
            Mock.Arrange(() => consoleArgumentsProvider.ConsoleArguments).Returns("ipconfig");
            Mock.Arrange(() => consoleArgumentsProvider.RetriesCount).Returns(2);
            Mock.Arrange(() => consoleArgumentsProvider.FailedTestsThreshold).Returns(50);
            var processExecutionProvider = Mock.Create <IProcessExecutionProvider>();

            Mock.Arrange(() => processExecutionProvider.ExecuteProcessWithAdditionalArguments(string.Empty)).DoNothing();
            Mock.Arrange(() => processExecutionProvider.CurrentProcessWaitForExit()).DoNothing();
            var fileSystemProvider = Mock.Create <IFileSystemProvider>();

            Mock.Arrange(() => fileSystemProvider.SerializeTestRun(Arg.IsAny <TestRun>())).DoNothing();
            TestRun testRun = new TestRun();

            testRun.Results = new TestRunUnitTestResult[]
            {
                new TestRunUnitTestResult(),
                new TestRunUnitTestResult()
            };
            testRun.ResultSummary         = new TestRunResultSummary();
            testRun.ResultSummary.outcome = "Failed";
            Mock.Arrange(() => fileSystemProvider.DeserializeTestRun(Arg.AnyString)).Returns(testRun);
            var microsoftTestRunProvider = Mock.Create <IMsTestTestRunProvider>();

            Mock.Arrange(() => microsoftTestRunProvider.GetAllPassesTests(Arg.IsAny <TestRun>())).DoNothing();
            Mock.Arrange(() => microsoftTestRunProvider.UpdatePassedTests(Arg.IsAny <List <TestRunUnitTestResult> >(), Arg.IsAny <List <TestRunUnitTestResult> >())).DoNothing();
            Mock.Arrange(() => microsoftTestRunProvider.UpdateResultsSummary(Arg.IsAny <TestRun>())).DoNothing();
            Mock.Arrange(() => microsoftTestRunProvider.GetAllNotPassedTests(Arg.IsAny <List <TestRunUnitTestResult> >())).Returns(new List <TestRunUnitTestResult>()
            {
                new TestRunUnitTestResult(), new TestRunUnitTestResult()
            });
            Mock.Arrange(() => microsoftTestRunProvider.GenerateAdditionalArgumentsForFailedTestsRun(Arg.IsAny <List <TestRunUnitTestResult> >(), Arg.AnyString)).DoNothing();
            Mock.Arrange(() => microsoftTestRunProvider.CalculatedFailedTestsPercentage(Arg.IsAny <List <TestRunUnitTestResult> >(), Arg.IsAny <List <TestRunUnitTestResult> >())).Returns(100);

            var engine = new TestExecutionService(
                microsoftTestRunProvider,
                fileSystemProvider,
                processExecutionProvider,
                consoleArgumentsProvider,
                log);
            int result = engine.ExecuteWithRetry();

            Mock.Assert(() => processExecutionProvider.ExecuteProcessWithAdditionalArguments(Arg.AnyString), Occurs.Once());
            Mock.Assert(() => fileSystemProvider.DeserializeTestRun(Arg.AnyString), Occurs.Once());
            Mock.Assert(() => microsoftTestRunProvider.GenerateAdditionalArgumentsForFailedTestsRun(Arg.IsAny <List <TestRunUnitTestResult> >(), Arg.AnyString), Occurs.Never());
            Mock.Assert(() => microsoftTestRunProvider.GetAllPassesTests(Arg.IsAny <TestRun>()), Occurs.Never());
            Mock.Assert(() => microsoftTestRunProvider.UpdatePassedTests(Arg.IsAny <List <TestRunUnitTestResult> >(), Arg.IsAny <List <TestRunUnitTestResult> >()), Occurs.Never());
            Mock.Assert(() => microsoftTestRunProvider.UpdateResultsSummary(Arg.IsAny <TestRun>()), Occurs.Never());
            Mock.Assert(() => fileSystemProvider.SerializeTestRun(Arg.IsAny <TestRun>()), Occurs.Once());
            Assert.AreEqual <int>(1, result);
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            string microsoftTestConsoleExePath = ConfigurationManager.AppSettings["MSTestConsoleRunnerPath"];
            var    consoleArgumentsProvider    = new ConsoleArgumentsProvider(args);
            var    engine = new TestExecutionService(
                new MsTestTestRunProvider(consoleArgumentsProvider, LogManager.GetLogger(typeof(MsTestTestRunProvider))),
                new FileSystemProvider(consoleArgumentsProvider),
                new ProcessExecutionProvider(microsoftTestConsoleExePath, consoleArgumentsProvider, LogManager.GetLogger(typeof(ProcessExecutionProvider))),
                consoleArgumentsProvider,
                LogManager.GetLogger(typeof(TestExecutionService)));

            try
            {
                engine.ExecuteWithRetry();
            }
            catch (Exception ex)
            {
                log.Error(string.Concat(ex.Message, ex.StackTrace));
            }
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            string microsoftTestConsoleExePath = ConfigurationManager.AppSettings["MSTestConsoleRunnerPath"];
            var    consoleArgumentsProvider    = new ConsoleArgumentsManager(args);
            var    engine = new TestExecutionService(
                new TestRunManager(),
                new MsTestProcessManager(microsoftTestConsoleExePath),
                consoleArgumentsProvider);

            try
            {
                int result = engine.ExecuteWithRetry();

                System.Console.Out.WriteLine("Exiting with code " + result);
                Environment.Exit(result);
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine(string.Concat(ex.Message, ex.StackTrace));
            }
        }