-
Notifications
You must be signed in to change notification settings - Fork 325
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
'dotnet test' in solution folder fails when non-test projects are in the solution #1129
Comments
From @bencyoung on September 4, 2017 14:26 We have the same issue. A filter or the ability to point it at a sub-directory would be great dotnet test tests/ or something like that... |
From @peterichens on September 4, 2017 15:17 Same problem here, the error thrown causes our CI to report failure. Ignoring projects without the test sdk would be good, or at least just logging a message/warning, rather than an error. |
From @kendrahavens on September 6, 2017 17:7 @pvlakshm Could you add the dotnet-test label? |
From @johncrim on September 22, 2017 18:10 Same issue appears to be covered here: Allow dotnet test to run on all test projects in a given directory #705. |
Same issue here. Please implement |
Same issue. It's causing my jenkins build to fail |
travis failing for me for the same reason |
The workaround I'm using right now is this script.
It simply strips out projects that don't end with
HTH |
I'm currently using these msbuild targets in the solution directory to work around this: A <Project>
<Target Name="VSTestIfTestProject">
<CallTarget Targets="VSTest" Condition="'$(IsTestProject)' == 'true'" />
</Target>
</Project> Then file named <Project>
<Target Name="VSTest">
<MSBuild Projects="@(ProjectReference)" Targets="VSTestIfTestProject" />
</Target>
</Project> |
@jcdickinson That script worked really well. I was able to get my build process to run the tests without failing. Thanks! |
I was just about to write the same bug. Seems this is not fixed yet in 2.0.3 and we have to use workarounds? |
UPDATEEven executing that command wasn't working right so I had to build this bash script to do the job. Now I just execute the bash script.
The best way to solve this is to place all of your Tests project into their own folder, which is relatively good practice to keep large projects manageable. So, let's assume a structure like this:
Now to run all tests you just use |
@consultwithmike I don't think it's reasonable to expect every developer or organization to restructure all their solutions to work around this. Only testing projects that have some test sdk as a dependency - or supporting some project name filter - seems to me like a much more reasonable expectation. |
@bungeemonkee I agree with you holistically because when I first encountered this I expected the same thing. But, since I had to work around it, I found this a very easy workaround that also made sense structurally. So then it seemed to make sense that this was a good approach regardless. |
@consultwithmike I'm glad you found a solution that works for you. I'm just making the point that the work-arounds are not viable options for everyone and that this is still an active issue for many of us. |
@consultwithmike when I run |
@lilasquared you're absolutely right. I just found that out myself when I moved another test project into that directory. So, I ended up having to build this bash script to do the work for me.
|
@consultwithmike thanks for sharing. I have done something similar in the past when using nunit test runners. it's a shame that it is so complicated to do something as simple as run tests still. Since my application is small enough perhaps i will keep all the tests in one project. |
While the current solution for @consultwithmike works, it might be convenient to run all your tests from a single command, to ease stat parsing. This can be achieved with For my project, this results in the following command (I know, the folders and casing are wrong, which is what you get when you maintain a .NET project originally created by Java developers):
It wil run all test in the dll's matching the argument selector, and give some final, accumulated output:
This method does not appear to be working from PowerShell. |
fyi I wrote a blog post about my solution (enables |
Well played @dasMulli - well played! |
@dasMulli Your method works, but it does result in several invocations of the test runner, leading to several output files and a longer execution time. It also does not generate an overview of all tests run in the end. Due to this, I personally prefer the |
In powershell I am using this:
Meaning "run all tests recursively in all sub-folders, where assemblies are named Pretty sure it could be improved (by using proper directory filtering instead of string match, for instance), but it gets the job done. |
It would be great if this would work out of the work! |
The |
guys, until this is properly fixed by MS, please have a look at @dasMulli solution above which works perfectly fine for me even considering that I have multiple solutions in the same folder |
Creating |
NOTE: To test run `dotnet test ./Tests` due to this bug (microsoft/vstest#1129).
@MohsenBzm for all projects or specific to this issue? If the First thing I ran into with |
@smadala Please pick this up for resolution as discussed. |
Is this going to work by literally looking for references to the MS Test SDK package, or instead for the flags that project sets like so: <ItemGroup>
<ProjectCapability Include="TestContainer" />
</ItemGroup>
<PropertyGroup>
<IsTestProject>true</IsTestProject>
</PropertyGroup> I strongly recommend it work by looking for those flags. If it looks for the SDK reference itself, that'd be quite limiting for non-MSTest frameworks. Non-MSTest frameworks today can avoid the need for an explicit test SDK reference by including these flags in their own nuget packages, which opens the door to important features such as those Fixie has:
There's been at least some talk of xUnit 3 treating test assemblies as truly-executable too, and they'll either need to do the same (avoid the SDK) or else they'll be pushing for the SDK package to become more flexible such as no longer inserting the empty Main() entry points. If issues like this one work with the flags, xUnit and friends won't break |
If anybody here accepts a sh solution: |
I'd still prefer a solution that would treat it as a single test run. all solutions involve invoking vstest multiple times, either through sh commands or looking at all projects with
|
@dasMulli What would a single test run really mean? Imagine your test project multitargets net47 and netcoreapp2. Those definitely have to be separate processes. |
@plioi As @dasMulli suggestions. Single invocation of Currently |
I agree with @plioi on the single |
* Add some missing method to LoggingHandler * Avoid to alloc an huge error message when the test not failed. * Update the unittest * Update Microsoft.NET.Test.Sdk from 15.0.0 to 15.7.2, fix that unable to debug an unittest for the second time. * Disable parallelization for InternalLoggerFactoryTest.TestMockReturned to avoid an rare test failure. * Remove `dotnet-xunit` since it's never used and will be discontinued, see https://xunit.github.io/releases/2.4-beta2 * Remove space from filename * Switch back to `DiscardSomeReadBytes` since it's avaliable * Rework some logic in TlsHandler * Make sure TlsHandler.MediationStream works well with different style of aync calls(Still not work for Mono, see Azure#374) * Rework some logic in Azure#366, now always close TlsHandler.MediationStream in TlsHandler.HandleFailure since it's never exported. * Workaround to fix issue 'microsoft/vstest#1129'. * Change the default of TcpServerSocketChannel.Metadata.defaultMaxMessagesPerRead to 1
@livarcocc I ran into the same issue. There's a quite good workaround for that: <Project>
<!--Override VSTest target when the project is no test project.-->
<Import Project="OverrideTest.targets" Condition="'$(IsTestProject)' != 'true'"/>
</Project> create the file OverrideTest.targets beside the Directory.Build.targets <Project>
<Target Name="VSTest">
</Target>
</Project> what happens here is that the VSTest target is overridden as empty (nothing happens) when the project is not considered as test project by msbuild. A better solution (reusable across many repositories) is to put that into an build nuget package and just reference that package in your Directory.Build.targets, but unfortunately I can't publish mine on nuget.org |
I know this could be a strange solution but I personally do the following.
The CLI would run tests only for test projects. Now when new Test project is added only a solution configuration has to be modified (no CI changes involved). Hope this helps. |
+1 to the requirement of 'works out of the box'. |
Add MSBuild test targets to make the test runner not search for tests within non-test projects as per the following: microsoft/vstest#1129 https://dasmulli.blog/2018/01/20/make-dotnet-test-work-on-solution-files/
For people who can't make it work with Travis: It started returning
to
|
I noticed that using dotnet 2.1.500 doing this
provides information that tests are skipped if they not include
Was the issue already fixed with a release?
but the same was not happening using a Linux Preview Host, reporting the same task information. |
To me it is working as expected on Finally, after more than 1 year waiting it works without workarounds! 🙂 |
@johnnyasantoss Thanks for confirming. Apologies, you had to wait this long, thanks for your patience. We are prioritizing issues like these and are committed to improving the experience. We are open to contributions from the community as well, so we can expedite resolution for such issues. |
From @bungeemonkee on August 15, 2017 16:1
Description
Being able to run 'dotnet test' on a solution now is amazing! However, unless that solution contains ONLY test projects it always produces a failure result due to not finding the test sdk. In my experience it is rare for tests to be in a separate solution - they generally don't exist or are in the same solution as the code they are testing.
It seems logical to me that when running tests on a solution any projects without the test sdk should be ignored. If a project has the test sdk and no tests or is being tested in isolation and does not have the sdk that is likely an error. However if a project does not have the sdk and is being tested as part of a solution that is likely not an error.
Alternatively, if that feels too much like a breaking change then adding an option to filter by patterns on the project name could suffice. Something like
dotnet test --projects "*.Tests.*"
. Since most test projects in my experience have some form of pattern to the name - usually involving the word 'test' - this would probably be sufficient for most cases.Note that the existing
--filter <EXPRESSION>
switch is insufficient to prevent the exception, presumably because it is processed by the underlying test framework which happens after the missing sdk error is thrown.Steps to reproduce
'''
dotnet new sln -n Solution
dotnet new console -n Program
dotnet sln Solution.sln add Program/Program.csproj
dotnet new mstest -n Tests
dotnet sln Solution.sln add Tests/Tests.csproj
dotnet test
$?
'''
Expected behavior
Actual behavior
Environment data
dotnet --info
output:.NET Command Line Tools (2.0.0)
Product Information:
Version: 2.0.0
Commit SHA-1 hash: cdcd1928c9
Runtime Environment:
OS Name: ubuntu
OS Version: 16.04
OS Platform: Linux
RID: ubuntu.16.04-x64
Base Path: /usr/share/dotnet/sdk/2.0.0/
Microsoft .NET Core Shared Framework Host
Version : 2.0.0
Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
What is not clear form this environment output is that I am running in bash via the WSL.
Copied from original issue: dotnet/cli#7447
The text was updated successfully, but these errors were encountered: