TheRoadrunner
TheRoadrunner

Reputation: 1489

How to use VSTest from Nuke builds

I am trying to use Nuke to run VSTest as some of my tests are in .Net Framework (not core).

I have a test running succesfully with:

VSTest(@".\test\MyTestProjectFolder\bin\Debug\net47\MyTestProject.dll");

...but I don't like to point into the bin\debug\net47 folder if I don't have to.

I would much prefer to point out the test project source, or even the solution.

Running

VSTest(@".\test\**\*.csproj");

returns an IReadOnlyCollection<Output> containing 9 instances of ? corresponding to my 9 test projects, but how to execute those, or select one or more to execute?

The fluent syntax is preferrable, just cannot figure it out.

Upvotes: 4

Views: 967

Answers (1)

Good Night Nerd Pride
Good Night Nerd Pride

Reputation: 8470

Disclaimer: I'm pretty new to nuke.

I'm afraid VSTest really only accepts paths to DLL files. This is how I constructed the path:

Target Test => _ => _
    .DependsOn(Compile)
    .Executes(() => {
        var proj = Solution.GetProject("Tests");
        var outDir = proj.GetMSBuildProject(Configuration).GetPropertyValue("OutputPath");
        var assembly = proj.Directory / outDir / "Tests.dll";
        VSTest(assembly);
    });

It's still not pretty or convenient at all, but at least the hard-coded path is partially gone.

Also I'm not sure about the net47 part in your path. I don't think its part of the OutputPath property. But GetMSBuildProject() takes a second optional parameter called targetFramework that could help with that.

Since you have multiple test projects you might find SetTestAssemblies(IEnumerable<string>) helpful:

VSTest(s => s.SetTestAssemblies(assemblies));

Upvotes: 2

Related Questions