-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow dotnet test to run on all test projects in a given directory #705
Comments
From @blackdwarf on May 21, 2016 17:35 @livarcocc @piotrpMSFT thoughts? |
From @piotrpMSFT on May 26, 2016 7:52 We need to think about this in the context of the new project model design... |
From @bojingo on June 30, 2016 23:24 Is there even a reason for the There could be some evaluation of the project.json file to ensure it is a valid test project, such as ensuring there is a testRunner property, such as |
From @dazinator on July 5, 2016 15:14
Yes please! Just setting up a CI build, and having to CD into each test project directory to run |
From @unjello on October 5, 2016 13:52 Any progress on that? |
From @MarinAtanasov on November 5, 2016 8:44 Fully agree. If I want to run multiple projects from PowerShell, the only way I've found is:
And the results are not easily readable because it runs every project separately. Also, somewhat related, we should be able to run all projects in a single run. Even in VS, every project seems to have a separate loading time (about 2 seconds) which slows down the test run when you have multiple test projects. |
From @glucaci on December 13, 2016 10:36 For example the I think this will be a good solution for Actualy cannot parse the argument:
|
From @petrsvihlik on January 14, 2017 19:59 @MarinAtanasov thanks! i've adjusted it a little bit for my project to run only in folders containing tests and to output the test results...
it'd be great if it supported running tests for multiple projects OOTB |
From @StrangeWill on April 11, 2017 16:28 Just ran into this today, we'd been using PowerShell for awhile but the problem comes when we want to test under dotCover and TeamCity (now supported on 2017.1 for .NET Core), to do that through PowerShell would be a pain... If |
There is a way to run multiple projects with a single command which returns a single summary for the results. However, you must build the projects/solution first. dotnet build SOLUTION.sln After this, you can use dotnet-vstest to execute the tests. In my case, all projects containing tests are under /test subdir: dotnet vstest (Get-ChildItem test | % { Join-Path $_.FullName -ChildPath ("bin/Debug/netcoreapp1.1/$($_.Name).dll") }) You don't need to use Powershell. You just need the path to all test assemblies. For example: dotnet vstest .\Project1\bin\netcoreapp1.1\Project1.dll .\Project2\bin\netcoreapp1.1\Project2.dll You can also add It will be nice to have a way to run the tests using dotnet-test while pointing to the solution file similar to building the solution in the first code snippet. |
Please supply a common |
Strange thing is this works on dotnet core 2.0.2 on my mac: dotnet test src\**.Tests
Build started, please wait...
Build completed.
Test run for
xxxx/src/Service.Tests/bin/Debug/netcoreapp2.0/Service.Tests.dll(.NETCoreApp,Version=v2.0)
Microsoft (R) Test Execution Command Line Tool Version 15.3.0-preview-20170628-02
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
[xUnit.net 00:00:00.5794770] Discovering: Service.Tests
[xUnit.net 00:00:00.6828850] Discovered: Service.Tests
[xUnit.net 00:00:00.7291560] Starting: Service.Tests
[xUnit.net 00:00:05.8853170] Finished: Service.Tests
Total tests: 8. Passed: 8. Failed: 0. Skipped: 0. And in also in PowerShell Core on my macbook: dotnet test src\**.Tests But this doesn't work on dotnet core 2.0.3 in PowerShell on my Windows machine:
|
Seriously, we have Linux (RHEL) ininfrastructure (bitbucket, jira, docker, jenkins) and basic commands of core cli (dotnet test) don't work in a proper way. We have no opportunity to get code coverage of solution on Linux (#981, https://github.com/dotnet/corefx/issues/17107). So, dotnet core is cross platform only on paper. |
@Kantuz001 I had the same problem with teamcity and found a solution. I run On linux, to run only tests projects, I use the following command :
|
It would be nice to create a solution just for test projects and do |
@EChaffraix our workaround, we use groovy
|
Does this append test results to a final result file?
…On Jan 9, 2018 5:13 AM, "Dmitriy Voznesenskiy" ***@***.***> wrote:
@EChaffraix <https://github.com/echaffraix> our workaround, we use groovy
case Constant.BUILD_TOOL_DOTNET:
List csprojTests = this.getShellStdout('ls -d $(pwd)/test/*').split('\n')
csprojTests.each { csprojTest ->
script.sh "dotnet test $csprojTest"
}
break
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#705 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACzG69rjysF8TWvEvPLKknc2RJ0eKOJTks5tI0nBgaJpZM4M6XON>
.
|
As a workaround, this PS snippet works for us:
|
Yeah, I'm not a fan of having to piggy-back on various scripting platforms (bash/powershell) because they're not portable (outside of Powershell Core, and I'm not a fan of pushing Powershell as a must on Linux for proper dotnet support). This concept should really be supported by our tool chain and not hacked around. Also not a fan of leaving it up to Many other actions can be taken at the solution level (restores, builds), I don't see why tests should be any different (from a UX standpoint, I understand the logistical differences on compiling tests into a larger unit of work). |
@altinoren the problem with that script is that you're not handling the failure of tests in an individual project. You're running the tests, displaying the output and ignoring the result of the run to continue onto the next test project. The marshalling of failures in individual projects is something that should be handled as part of a solution test option in my opinion. |
We worked around the issue by running "dotnet test" in a loop. We use CAKE and Bamboo. Bamboo is capable of parsing as many .trx files that it finds via the MSTest Parser task and I would wager most other CI/CD solutions can do this as well. If Bamboo finds failed tests, the Bamboo build fails, so we do not suffer from the issue @cfletcher has cautioned. BTW, xunit.console.runner is now depreciated. CAKE///////////////////////////////////////////////////////////////////////////////
// Test
///////////////////////////////////////////////////////////////////////////////
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
// Clear out the old test results
CleanDirectories(new DirectoryPath[] { testArtifacts });
// Build up assemblies
var projects = GetFiles($"./tests/**/*.csproj");
foreach(var project in projects)
{
Information($"Preparing {project.GetFilename()}");
var settings = new DotNetCoreTestSettings()
{
Logger = $"trx;logfilename={project.GetFilenameWithoutExtension()}.trx",
ResultsDirectory = testArtifacts
};
DotNetCoreTest(project.FullPath, settings);
}
}); |
This would also be of benefit when using |
Once again, another issue our dev team has ran into when attempting to slowly shift to using .NET core / standard. These problems are not obvious when playing around with a new technology. But when you start to migrate an enterprise solution you realise that there are still a lot of rough edges in the tooling that makes life very annoying when trying to configure things like your CI pipeline. We currently use NUnit for our .NET framework test projects. We have a step in TeamCity which uses the NUnit command line to run the tests in the solution. Low and behold, the command line doesn't work for .NET core projects. Do some more googling - OK cool the solution is to use the inbuilt "dotnet test" command. That actually sounds great! OK how do I call "dotnet test" on a solution instead of an individual project... that doesn't exist? Hmph.. So now I have to explicitly list each .net core test project in our solution on Teamcity... and then when a coworker adds another test project a month from now we have to remember to add that project in TC. I was originally surprised I hadn't seen hundreds of "arms waving" blog posts from dev teams shifting enterprise solutions to .NET core - but now am thinking they are too busy hacking workarounds to actually get time to write a blog post. |
@nzandy Core is still maturing and they are using feedback from people like us to constantly improve it. I will say, before you write your blog post take the time here to read some of the solutions that others have come up with for solving this problem. If you are moving to core, you should follow best practices and put your test projects in a "tests" folder which will make them incredibly easy to glob in either bash, powershell or CAKE, PSAKE, whatever you want to use. I personally recommend CAKE with core. You should never have to do this, if you do, your structure is wrong:
|
Appreciate the comment @VictorioBerra - Currently our solution is structured in a way that the test projects sit alongside the projects they test (for example /Customers/Customers.Domain and /Customer/Customer.Domain.Tests folders). So it would be easy to iterate over all folders ending with *.Tests/ in powershell. However because currently we use the NUnit command line for running the .NET framework tests I would not want to run these again by doing a broad iteration like that. For now because the number of projects is small I am going to explicitly refer to each .NET core tests project - I think the end goal would be just using "dotnet test" for all test projects (.NET framework included) but that (may?) require some further changes to the .NET framework test projects first. |
@livarcocc ya this sucks. I thought this was a good solution but the Globbing works everywhere but windows. We should fix this. @DamianEdwards
|
I am so glad this is being highlighted. Consistent usage of globbing capability in CLI commands for the win! :-) |
@livarcocc this is quite a long thread and after reading all the comments I unfortunately don't see the solution for running all the tests (at least at the test class level) for a given list of test projects using the Do you or anyone else have a suggestion?
Since I noticed during my testing dotnet test still calls VSTest as the target (took time to figure this out too) I tried to pass in the parallel parameter like this:
but it fails with error message For switch syntax, type "MSBuild /help"` |
@vikasillumina We are working on fixing the issue of running tests from different projects in a solution and should have an update soon. If there's a repro for your issue, please do share it so that it is validated as well. |
I'm confused why most of you can't just parse all the resulting test result files in your CI/CD environment like Bamboo, Jenkins, VSTS/TFS, TeamCity, you name it. All of those support parsing a variety of test result files and as many as you need. |
@VictorioBerra using your solution means every time you add a new test project to your solution, you then have to remember to go and update the static list of test files in your CI server, Alternatively you can create a hacky bit of powershell that iterates over some pre-defined folder structure convention, which is not viable in many use cases. In-built support of running all test projects in a solution is the only legitimate way for this to be resolved. |
@VictorioBerra that's what most of us do. It means additional work. We don't wont to do that. It adds no value. Having test and non-test projects in one solution is a common approach. Running all tests in a solution is a common use case. |
@nzandy that's not true at all. Most test result parsers can glob. Just output your test results to the same folder. That's not even remotely hacky. If you keep all your tests in a folder structure then you can loop and run your tests. See my cake example above. Literally the only difference between my solution and the solution everyone is asking for is one single loop to run tests. |
@VictorioBerra for me, the argument doesn't involve a CI system. I just want to go into a solution and type 'dotnet test' pre-commit. I was pretty surprised that didn't work. |
I can sympathize. Considering commands like |
any progress on this? |
This is a bit hacky but is working for me for now:
This watches changes and also filters down to test projects only. Not ideal, but it does allow me to keep all my tests rebuilding and running the background across multiple test projects. |
Seems like they answered our requests and slipped in a new feature:
dotnet --version: 2.1.500 |
Indeed it is. With dotnet version 2.1.500, one can now run tests at the solution level without having to create another Testsln only for tests. Thanks for confirming @riezebosch. |
The IsTestProject property is indeed nice, but is still incomplete IMO. The filtering of test projects is great, but now there is a bunch of noise for projects that are skipped due to: <!-- Microsoft.TestPlatform.targets, Line 55 -->
<Target Name="ShowInfoMessageIfProjectHasNoIsTestProjectProperty"
Condition="'$(IsTestProject)' != 'true'">
<Microsoft.TestPlatform.Build.Tasks.VSTestLogsTask
LogType="NoIsTestProjectProperty"
ProjectFilePath="$(MSBuildProjectFullPath)" />
</Target> Arguably, the Condition should be something like: <Target Name="ShowInfoMessageIfProjectHasNoIsTestProjectProperty"
Condition="'$(IsTestProject)' != 'true' AND '$(IsTestProject)' != 'false'">
<Microsoft.TestPlatform.Build.Tasks.VSTestLogsTask
LogType="NoIsTestProjectProperty"
ProjectFilePath="$(MSBuildProjectFullPath)" />
</Target> This would still allow the filtering of test projects, but can suppress emitting messages about skipped projects when the IsTestProject is explicitly set to Not sure if that warrants an entirely new issue, but that would be nice. :) |
I agree with the previous comment. Additionally, it would be better if |
Any way of running separate project in parallel with |
@commonsensesoftware I tried fixing that issue differently based on another feedback. If IsTestProject is defined, skip the message. #1867 |
I would request folks to create a new issue for any asks post this. Thanks. |
From @sunsided on May 19, 2016 17:6
For continuous integration, I want to be able to run
dotnet test
on all test projects in thetest
directory of my solution, without having to explicitly configure each subdirectory manually, by e.g. issuingor
from the solution directory.
Steps to reproduce
In the solution directory, run
Expected behavior
Runs all tests in
test
subdirectory.Actual behavior
Environment data
Copied from original issue: dotnet/cli#3136
The text was updated successfully, but these errors were encountered: