Пример #1
0
        public GivenATestCommand()
        {
            _dotnetTestRunnerMock = new Mock<IDotnetTestRunner>();
            _dotnetTestRunnerMock
                .Setup(d => d.RunTests(It.IsAny<ProjectContext>(), It.IsAny<DotnetTestParams>(), It.IsAny<BuildWorkspace>()))
                .Returns(0);

            _dotnetTestRunnerFactoryMock = new Mock<IDotnetTestRunnerFactory>();
            _dotnetTestRunnerFactoryMock.Setup(d => d.Create(null)).Returns(_dotnetTestRunnerMock.Object);

            _testCommand = new TestCommand(_dotnetTestRunnerFactoryMock.Object);
        }
Пример #2
0
        public static int Run(string[] args)
        {
            var testCommand = new TestCommand(new DotnetTestRunnerFactory());

            return testCommand.DoRun(args);
        }
Пример #3
0
        public static TestCommand FromArgs(string[] args, string msbuildPath = null)
        {
            var parser = Parser.Instance;

            var result = parser.ParseFrom("dotnet test", args);

            UpdateRunSettingsArgumentsText();
            result.ShowHelpOrErrorIfAppropriate();

            var parsedTest = result["dotnet"]["test"];

            var msbuildArgs = new List <string>()
            {
                "-target:VSTest",
                "-nodereuse:false", // workaround for https://github.com/Microsoft/vstest/issues/1503
                "-nologo"
            };

            msbuildArgs.AddRange(parsedTest.OptionValuesToBeForwarded());

            msbuildArgs.AddRange(parsedTest.Arguments);

            var runSettingsOptions =
                result.UnparsedTokens
                .Select(GetSemiColonEscapedString);

            if (runSettingsOptions.Any())
            {
                var runSettingsArg = string.Join(";", runSettingsOptions);

                msbuildArgs.Add($"-property:VSTestCLIRunSettings=\"{runSettingsArg}\"");
            }

            var verbosityArg = parsedTest.ForwardedOptionValues("verbosity").SingleOrDefault();

            if (verbosityArg != null)
            {
                var verbosity = verbosityArg.Split(':', 2);
                if (verbosity.Length == 2)
                {
                    msbuildArgs.Add($"-property:VSTestVerbosity={verbosity[1]}");
                }
            }

            bool noRestore = parsedTest.HasOption("--no-restore") || parsedTest.HasOption("--no-build");

            TestCommand testCommand = new TestCommand(
                msbuildArgs,
                parsedTest.OptionValuesToBeForwarded(),
                parsedTest.Arguments,
                noRestore,
                msbuildPath);

            var rootVariableName = Environment.Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)";

            if (Environment.GetEnvironmentVariable(rootVariableName) == null)
            {
                testCommand.EnvironmentVariable(rootVariableName, Path.GetDirectoryName(new Muxer().MuxerPath));
            }

            return(testCommand);
        }