示例#1
0
        public void Execute_DotNet_Test_Command_Line()
        {
            var dotNetTestRunner      = new DotNetTestRunner(_rpcServerMock, _process);
            var coverageContext       = new CoverageContext();
            var testProjectOutputPath = "bin/debug";

            dotNetTestRunner.Run(coverageContext, testProjectOutputPath);

            _process.Received(1).Execute(Arg.Is("dotnet"), Arg.Is("test --no-build"), Arg.Any <string>());
        }
        public async Task RunTestsAsync_WhenRunningAndAllTestPassFromANonCoreProject_ShouldGetCorrectResult()
        {
            var testDllPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Samples", "NonCore", "NUnit", "PassingTests", "NunitTestProject.dll");

            var dotNetRunner = new DotNetTestRunner(null, TimeSpan.FromSeconds(5));
            var result       = await dotNetRunner.RunTestsAsync(testDllPath);

            Assert.IsTrue(result.IsSuccess, "Test result should be successful");
            Assert.AreEqual(2, result.TestResults.Count, "Wrong test result count");
            Assert.AreEqual(2, result.TestResults.Count(t => t.IsSuccess), "Should find two test that pass");
        }
        public async Task RunTestsAsync_WhenRunningAndProjectCont_ShouldGetCorrectResult(string type, string dllName)
        {
            var testDllPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Samples", type, "WithErrors", dllName);

            var dotNetRunner = new DotNetTestRunner(null, TimeSpan.FromSeconds(5));
            var result       = await dotNetRunner.RunTestsAsync(testDllPath);

            Assert.IsFalse(result.IsSuccess, "Test result should not be successful");
            Assert.IsTrue(result.Name.StartsWith("ERROR"));
            StringAssert.Contains("was not found", result.Name);
        }
        public async Task RunTestsAsync_WhenRunningAndSomeUnitTestFail_ShouldGetCorrectResult(string type, string dllName)
        {
            var testDllPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Samples", type, "FailingTests", dllName);

            var dotNetRunner = new DotNetTestRunner(null, TimeSpan.FromSeconds(5));
            var result       = await dotNetRunner.RunTestsAsync(testDllPath);

            Assert.IsFalse(result.IsSuccess, "Test result should not be successful");
            Assert.AreEqual(2, result.TestResults.Count, "Wrong test result count");
            Assert.IsTrue(result.TestResults.Any(t => t.IsSuccess), "Should find one test that pass");
            Assert.IsTrue(result.TestResults.Any(t => !t.IsSuccess), "Should find one test that fail");
        }
示例#5
0
        public void Start_Rpc_Server_Before_Running_Tests()
        {
            var dotNetTestRunner      = new DotNetTestRunner(_rpcServerMock, _process);
            var testProjectOutputPath = "bin/debug";
            var coverageContext       = new CoverageContext();

            dotNetTestRunner.Run(coverageContext, testProjectOutputPath);

            Received.InOrder(() =>
            {
                _rpcServerMock.Start(Arg.Any <CoverageContext>());
                _process.Execute(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
            });
        }
示例#6
0
        public static async Task Run(string[] args)
        {
            // Get the configuration path
            string configurationPath = args.FirstOrDefault();

            if (string.IsNullOrWhiteSpace(configurationPath))
            {
                throw new ArgumentException("A configuration path must be specified.");
            }

            // Read the configuration
            string        text          = File.ReadAllText(configurationPath);
            Configuration configuration = JsonConvert.DeserializeObject <Configuration>(text);

            // Decode the configuration values
            Uri workingDirectory = new Uri(Environment.CurrentDirectory, UriKind.Absolute);

            Uri[] testProjectUris = configuration.GetTestProjectUris(workingDirectory);
            Uri[] changes         = configuration.GetChanges(workingDirectory);

            if (testProjectUris.Length == 0)
            {
                Console.WriteLine("No test projects.");
                return;
            }

            if (changes.Length == 0)
            {
                Console.WriteLine("No changes to test.");
                return;
            }

            // Get the affected projects
            Project[] projects = testProjectUris
                                 .ReadProjects()
                                 .GetAffectedByChanges(changes);

            // Build and run tests
            ITestRunner runner = new DotNetTestRunner();

            foreach (Project project in projects)
            {
                Console.WriteLine();
                Console.WriteLine($"----- {project.GetShortName()} -----");
                await project.Test(runner);
            }
        }
示例#7
0
        public void Disregard_Lack_Of_Trailing_slash()
        {
            var    dotNetTestRunner = new DotNetTestRunner(_rpcServerMock, _process);
            var    coverageContext  = new CoverageContext();
            string testProjectOutputPath;
            string expectedProjectName;

            if (IsWindows)
            {
                testProjectOutputPath = @"c:\git\project\src\projectname\bin\debug\netcoreapp1.1";
                expectedProjectName   = @"c:\git\project\src\projectname";
            }
            else
            {
                testProjectOutputPath = @"/home/user/git/project/src/projectname/bin/debug/netcoreapp1.1";
                expectedProjectName   = @"/home/user/git/project/src/projectname";
            }

            dotNetTestRunner.Run(coverageContext, testProjectOutputPath);

            _process.Received(1).Execute(Arg.Any <string>(), Arg.Any <string>(), Arg.Is(expectedProjectName));
        }