formulahendry / vscode-dotnet-test-explorer

.NET Core Test Explorer for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=formulahendry.dotnet-test-explorer
MIT License
204 stars 97 forks source link

Auto-Detect NUnit tests in the same project #197

Closed MartinHaeusler closed 5 years ago

MartinHaeusler commented 5 years ago

Hi,

I just tried to use your plugin. I've got a very simple C# project, two root folders "main" and "test" separate test code from production code.

It would be very handy if your plug-in could search for Nunit tests within the current project, rather than requiring a dedicated "Test Project". Running the tests from the CodeLens-links works fine in VSCode, but unfortunately your plugin doesn't detect them.

stefanforsberg commented 5 years ago

Hello, we do not require a dedicated "test project", but we do need to know how to discover your tests.

Is there a .sln or .csproj file in your root folder (eg the folder containing main and test) or can you elaborate a bit more about what your setup is?

MartinHaeusler commented 5 years ago

It's a really basic setup - I only did a dotnet new console in an empty folder. This creates a new .csproj file. In this root, I have one folder for the actual project .cs files, and one for the tests.

Then I added NUnit to the project:

dotnet add package Microsoft.NET.Test.Sdk dotnet add package Nunit3TestAdapter dotnet add package NUnit

Maybe not all of them are required, I followed a guide. Then I added a test.cs file to the test folder, containing a class with a method annotated as [Test].

This test can be executed just fine using the microsoft C# plugin. Unfortunately it doesn't show up in the .NET Test Explorer provided by this plug-in.

Do you think this might be added to the plugin? Or did I do somthing wrong? I'm coming from the Java world, C# is still new territory for me.

stefanforsberg commented 5 years ago

If I follow that guide the test explorer is working as expected.

When you say that the plugin doesn't detect them, what do you mean? If you look at the test explorer view what do you see?

image

MartinHaeusler commented 5 years ago

Hi,

sorry but I get a different result... Here are the sources of my "project": netCoreProject.zip

For me it looks like this:

projectExplorer

... and the .NET Test Explorer view says: testExplorer

I tried setting the test project path in the settings (to the same project which is currently open), but unfortunately the situation did not change.

Am I doing something wrong in my setup? As I said, I can run the tests just fine with the CodeLens commands, I just don't see them in the .NET test explorer.

stefanforsberg commented 5 years ago

When I open your project I can see the test explorer.

If you in a terminal window that's in the root directory (where the netCoreProject.csproj is located) and you run the command "dotnet test -t -v=q" what do you see then?

MartinHaeusler commented 5 years ago

I ran the command dotnet test -t -v=q and indeed it lists all my test methods in the console.

MartinHaeusler commented 5 years ago

I just realized that there's a "Show Log" button in the .NET Test Explorer header. Here's what it says:

Starting extension Finding projects for pattern d:\projects\netCoreProject/ Found 1 matches for pattern in folder d:\projects\netCoreProject Evaluating match d:/projects/netCoreProject/ Adding directory d:/projects/netCoreProject/ Executing dotnet test -t -v=q in d:/projects/netCoreProject/ Executing dotnet test -t -v=q in d:/projects/netCoreProject/

Looks alright to me? When I run the command manually in the VSCode integrated terminal I get a listing of all test methods.

stefanforsberg commented 5 years ago

Hmm yea that looks like an expected outcome.

If you execute "dotnet --version" in a terminal, what is shown then?

MartinHaeusler commented 5 years ago

Hi, sorry for the late reply, busy times...

The output of dotnet --version produces 2.1.101.

MartinHaeusler commented 5 years ago

Here's the list of the plugins I currently have installed:

... maybe something is conflicting here?

stefanforsberg commented 5 years ago

Ah ok, as noted on the prereq notes you need to run a higher version of the sdk when using nunit (https://github.com/formulahendry/vscode-dotnet-test-explorer#prerequisites). Try and upgrade your sdk version and see if that helps.

MartinHaeusler commented 5 years ago

Oh gosh. Thanks for the pointer, I totally missed that (perhaps you could add a warning in the UI somewhere if the prerequisites aren't met?).

Microsoft just made me jump through quite some hoops to get this working (I'm leaving this description here just in case someone else bumps into the same problem):

And now, after all this, plus restarting my computer about 3 times (because Microsoft), I'm finally able to see my tests in the .NET Test explorer.

I can also click "play" and in the "Test Explorer" log in VSCode it is clearly running the tests to completion, but unfortunately the .NET Explorer UI doesn't update - the spinning indicator just keeps on spinning even though the tests are long done. Any tips for that one?

stefanforsberg commented 5 years ago

@MartinHaeusler It might be that vscode lacks access to read the test result. Check out https://github.com/formulahendry/vscode-dotnet-test-explorer#test-result-is-not-shown-in-codelens--tree and see if that helps.

stefanforsberg commented 5 years ago

I'll close this issue since the issue title no longer is relevant.