Skip to content
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

Open Test from Test Explorer Does Nothing #1457

Open
6 of 25 tasks
dcdraper opened this issue Mar 28, 2019 · 51 comments
Open
6 of 25 tasks

Open Test from Test Explorer Does Nothing #1457

dcdraper opened this issue Mar 28, 2019 · 51 comments

Comments

@dcdraper
Copy link

dcdraper commented Mar 28, 2019

Visual Studio - Can no longer open test (F12) from Test Explorer, attempts do nothing

SpecFlow Version:

  • 3.0
  • 2.4
  • 2.3
  • 2.2
  • 2.1
  • 2.0
  • 1.9

Used Test Runner

  • SpecFlow+Runner
  • MSTest
  • NUnit
  • Xunit

Version number:

Visual Studio Version

  • VS 2017
  • VS 2015
  • VS 2013

Are the latest Visual Studio updates installed?

  • Yes
  • No

.NET Framework:

  • >= .NET 4.5
  • before .NET 4.5
  • .NET Core 2.0
  • .NET Core 2.1
  • .NET Core 2.2
  • .NET Core 3.0

Test Execution Method:

  • Visual Studio Test Explorer
  • TFS/VSTS/Azure DevOps – Task – PLEASE SPECIFY THE NAME OF THE TASK
  • Command line – PLEASE SPECIFY THE FULL COMMAND LINE

<SpecFlow> Section in app.config

<specFlow>
    
    <stepAssemblies>
      <!-- This attribute is required in order to use StepArgument Transformation as described here; 
    https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Step-argument-transformations  -->
      <stepAssembly assembly="SpecFlow.Assist.Dynamic" />
    </stepAssemblies>
  </specFlow>

Repro Project

Issue Description

Steps to Reproduce

  1. Right-click a test in Test Explorer, choose "Open Test"
  2. Or - Select a test in Test Explorer and press F12
  3. Observe that nothing happens
    Expected: The feature file will open and the selected test will be in focus, like it was in SpecFlow2.x
@dcdraper
Copy link
Author

This is a productivity killer for sure, since we are working with numerous feature files and test order does not match since they get automatically sorted in Test Explorer. I had to revert to 2.x until this gets fixed :(

@nuzolx
Copy link

nuzolx commented Mar 28, 2019

I have upgrade today, same configuration as you and for me it works.

@dcdraper
Copy link
Author

@nuzolx good news for you :) I will try again another day, too much time spent on this for me.

@ghost
Copy link

ghost commented Apr 1, 2019

Have the same bug!

@SabotageAndi
Copy link
Contributor

Please provide an example to reproduce this issue.

@ghost
Copy link

ghost commented Apr 2, 2019

After update to newest speclfow my Test Explorer window in VS 2017 doesn't show any tests.
Vs 2017
The newest Specflow for VS 2017 extension
NUnit 3.11
NUnit.Console.Runner 3.10
NUnit3TestAdapter 3.13
Specflow 3.0.188
Specflow.Tools.MsBuild.Generation 3.0.188
Specflow.NUnit 3.0.188

I did no changes after update specflow except removed config about nunit runner from app.config.
My project is in .net framework 4.7.2

Problem fixed after move this lines at the bottom of csproj file:

    <Target Name="AfterUpdateFeatureFilesInProject">
    <!-- include any files that specflow generated into the compilation of the project, if it was not included yet -->
    <ItemGroup>
      <Compile Include="**\*.feature.cs" Exclude="@(Compile)" />
    </ItemGroup>
  </Target>

@rik-smeets
Copy link

I experience this issue too. It seems to be caused by the new way in which the generated code is not longer included in the .csproj. If you click on the test, you will see 'Source: no source available'.

Previously, the generated code was part of the .csproj like this:

    <Compile Include="Test.feature.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Test.feature</DependentUpon>
    </Compile>

If you keep this code in the projectfile for your feature files after migrating, opening the test from the test explorer will still work. A source is then available too.

Another option is: simply include the generated file as part of your solution. However, this will bloat the view in the Solution Explorer by having both the .feature file and the .feature.cs at the main level (while the previously generated files were a level below the .feature file).
This solution looks like this in the .csproj:

<Compile Include="Test.feature.cs" />
<None Include="Test.feature" />

Both solutions require manual labour in the .csproj file, which is a step back from the previous versions of SpecFlow.

Note: when simply adding a .feature file and removing the SpecFlowSingleFileGenerator from the properties, the new test isn't even visible in the test explorer until doing either one of the aforementioned solutions, or unloading and reloading the project.

@SabotageAndi
Copy link
Contributor

I repeat, I need a project to reproduce this issue. Complete to clone from where, no step for step description.

Jumping from the test explorer to the feature file works in the SpecFlow solution. There we are using xUnit.

So please provide us one. Thanks!

@dcdraper
Copy link
Author

dcdraper commented Apr 3, 2019

@SabotageAndi I will try to create a test project when I get a chance to do so :-( Sorry I cannot do that right now, since I really do not want to move away from SpecFlow.
I am using Nunit, as indicated in my initial report.

@marcel-landman
Copy link

@rik-smeets work around worked for me (using mstest.testframework). Some additional notes:

  • <Compile Include Should be in an unconditional <ItemGroup> under <Project>
  • I had to delete this section created following the "msbuild" instructions for upgrading to version 3:
  <Target Name="AfterUpdateFeatureFilesInProject">
    <ItemGroup>
      <Compile Include="**\*.feature.cs" Exclude="@(Compile)" />
    </ItemGroup>
  </Target>
  • The final result looked like this:
<Project ToolsVersion...>
...
<ItemGroup>
  <None Include="Test.feature" >
  <Compile Include="Test.feature.cs">
    <AutoGen>True</AutoGen>
     <DesignTime>True</DesignTime>
     <DependentUpon>Test.feature</DependentUpon>
  </Compile>
  ...
</ItemGroup>
...
</Project>
  • @rik-smeets second option did not work for me, but perhaps I misunderstood.

@SabotageAndi
Copy link
Contributor

And if I would get a project to reproduce it, I could fix it correctly for all ....
We could include the whole itemgroup->dependentupon stuff in the csproj in our msbuild files so there is no need to have this lines for every file in your project.

@rik-smeets
Copy link

@SabotageAndi I think I can get around to creating an example project for it this Sunday.

@rik-smeets
Copy link

@SabotageAndi I created an example project for it over at https://github.com/rik-smeets/specflow-3-test-explorer. In the feature files is a description of the occurring issue and the possible workarounds as I described before. Let me know if you need any further information or help. Thanks!

@SabotageAndi SabotageAndi self-assigned this Apr 8, 2019
@SabotageAndi SabotageAndi added the SpecFlow Team Backlog this issue are in the backlog of the SpecFlow Team label Apr 8, 2019
@SabotageAndi
Copy link
Contributor

@rik-smeets thanks for the repro project. I can reproduce the issue.

I think it's because it is a project in the old format.

For the new format we do this: https://github.com/techtalk/SpecFlow/blob/master/SpecFlow.Tools.MsBuild.Generation/build/SpecFlow.Tools.MsBuild.Generation.targets#L40

 <Compile Update="@(SpecFlowFeatureFiles->'%(CodeBehindFile)')"
             DependentUpon="%(Filename)"
             AutoGen="true"
             DesignTime="true"
             Visible="true"
             Condition="'$(EnableDefaultCompileItems)' == 'true'" />

But it looks like, this doesn't work with the old format.

@rik-smeets
Copy link

@SabotageAndi Thanks for your analysis. What do you mean with 'old format'? Do you mean compared to .NET Core projects?

The repro project is a new solution/project, created from scratch in Visual Studio 2019, targeting .NET Framework 4.7.2. I didn't change anything to the defaults.

@SabotageAndi
Copy link
Contributor

old project format is the long one, where a lot of stuff is in the xml file.
The sdk- style format (the new one) is the one that was introduced in VS2017 and is mostly used for .NET Core. But you can also use it for .NET Full Framework.

@rik-smeets
Copy link

Alright, thank you. Do you think this issue can be resolved within the possible limitations of the old .csproj format?

@SabotageAndi
Copy link
Contributor

I am not sure. I have to talk with a colleague who is a master of MSBuild.

@dcdraper
Copy link
Author

@SabotageAndi Hello there. Have you discovered any more information on this or perhaps have a workaround documented somewhere on how to handle/correct the old .csproj format?
Also, I may have time to create a test project that uses NUnit if it would still be helpful to get this worked out...

@SabotageAndi
Copy link
Contributor

@dcdraper Nothing new to report. As written I can reproduce it, but had no success with fixing it.
I would suggest to migrate to the new csproj format. If you aren't doing really strange things, it's quite easy to do.

@SabotageAndi SabotageAndi added up-for-grabs and removed SpecFlow Team Backlog this issue are in the backlog of the SpecFlow Team labels Apr 25, 2019
@SabotageAndi
Copy link
Contributor

I had yesterday a talk with @DanielTheCoder about this issue.
What we are doing to link the generated files to the feature files (https://github.com/techtalk/SpecFlow/blob/master/SpecFlow.Tools.MsBuild.Generation/build/SpecFlow.Tools.MsBuild.Generation.targets#L40), doesn't work in the old csproj format, because it doesn't recognize the update of the ItemGroup.

There is nothing we can do about it automatically. :-/

@rik-smeets
Copy link

@SabotageAndi Thanks for your analysis.

I migrate projects to the new csproj format where possibly, but in some cases (like with non-Core ASP.NET applications), this isn't a possibility.

Perhaps there is a solution (sort of)... If the SpecFlow extension detects that the 'classic' .csproj format is used, then it should insert this in the .csproj (which I now do manually to make sure tests can be opened from test explorer, as I explained before):

    <Compile Include="[feature name].feature.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>[feature name].feature</DependentUpon>
    </Compile>

Just like with SpecFlow <3, but of course still without the SpecFlowSingleFileGenerator.

What do you think about that?

@SabotageAndi SabotageAndi removed their assignment May 9, 2019
@LirazShay
Copy link
Contributor

The solution of @sjeanren has many problems.
It works for existing items.
When I add new feature, then the cs file is not added.
Only when restarting Visual studio and the project is loaded, then the new cs file is added

@sjeanren
Copy link

In deed, it's just an improvement of the workaround, to avoid to add each feature one by one.
But, as explained by LirazShay, it has some problems.

@varajan
Copy link

varajan commented Sep 24, 2019

So to fix this issue we should convert our CSPROJ files to new format, e.g. like described here?

@SabotageAndi
Copy link
Contributor

@varajan Yes

@rloomans1980
Copy link

Hi @rik-smeets,

I am encountering the same issue. I've followed your steps exactly, but I am still not able to use the test explorer to navigate to my tests. It is still saying "source not available".
Vs2019
NUnit 3 Test Adapter extension 3.15.1.0
SpecFlow 3.1.67 (with all other stuff required).

DId anybody else experience the same problems? Am i missing something?

Thnx in advance.

@donvnielsen
Copy link

@rik-smeets I'm encountering the issue when running vs2019; "Go To Test" fails. I cannot go to a test from test explorer. But all appears fine when I regress back to vs2017.

VS2017 Test Explorer - ApplicationDisplaysListofAvailableTabs appears once (correct)
image

VS2019 Test Explorer - ApplicationDisplaysListofAvailableTabs appears twice (incorrect)
image

@darrendeng777
Copy link

darrendeng777 commented Jun 3, 2020

Hi @rik-smeets,

I am encountering the same issue. I've followed your steps exactly, but I am still not able to use the test explorer to navigate to my tests. It is still saying "source not available".
Vs2019
NUnit 3 Test Adapter extension 3.15.1.0
SpecFlow 3.1.67 (with all other stuff required).

DId anybody else experience the same problems? Am i missing something?

Thnx in advance.

I actually solved the issue by remove *.feature.cs from in csproj file

@jarjarbinks9999
Copy link

Hi
I am trying to create a test and run using Ms test, .net framework 472.
I can see the test,it builds alright and if it click on it it takes me to the feature file. However when I try to run or debug it does not run and appears under the not run tab.

Please can anybody advise?
Thanks

@rik-smeets
Copy link

@jarjarbinks9999
Are you sure you have installed both the MSTest.TestFramework and the MSTest.TestAdapter NuGet packages in your test project(s)?

@jarjarbinks9999
Copy link

jarjarbinks9999 commented Jun 18, 2020 via email

@LirazShay
Copy link
Contributor

@SabotageAndi
Hi,
Any news about this issue?
Is it going to be fixed soon please?

@larisa31grecu
Copy link

I recently migrated to Specflow 3.4.31 and I have the same issue in Visual Studio 2019. Test explorer shows "No source available" for my specflow tests, so double click will not end up going to the actual specflow test (feature file). Any updates regarding this? It would be a nightmare to migrate to the new csproj format in my case.

@peraltakeit
Copy link

Hello, has there been any progress regarding this issue? I recently started to get this and tried to apply @rik-smeets workaround but it does nothing for me.

@michaelhuang1168
Copy link

Hi, any update regarding this issue?

@SabotageAndi
Copy link
Contributor

@peraltakeit & @michaelhuang1168 Are you using the old csproj format or the SDK- csproj format?

@peraltakeit
Copy link

peraltakeit commented Jan 28, 2021

I converted it to 2019 format following @rik-smeets workaround (but I believe all the projects in my solution used to have the old csproj format), does that still count as the old csproj format? I am quite new to this so sorry if its a stupid question.

@michaelhuang1168
Copy link

michaelhuang1168 commented Jan 28, 2021

@SabotageAndi I just converted the csproj to the new format and it's working now.
This is the tool I used to convert my csproj file https://github.com/hvanbakel/CsprojToVs2017

@peraltakeit
Copy link

that is the exact same tool i used. does it matter that i am using specflow+runner instead of nunit runner?

@ashafi1430
Copy link

ashafi1430 commented Mar 14, 2022

Hi,
I've created a new .Net (4.7.2) project using VS 2019 Pro, Specflow Extension, and the following packages:

BoDi" version="1.5.0"
Gherkin" version="19.0.3"
Newtonsoft.Json" version="10.0.3"
NUnit" version="3.13.1"
NUnit3TestAdapter" version="4.1.0"
SpecFlow" version="3.9.50"
SpecFlow.Internal.Json" version="1.0.8"
SpecFlow.NUnit" version="3.9.50"
SpecFlow.Tools.MsBuild.Generation"
System.ValueTuple" version="4.4.0"

feature.cs file generation is generating at build time.,
I am able to see and run tests via test explorer, but unable to use test explorer to navigate to the feature files. This is becoming a problem when dealing with hundreds of feature files.

Is there a permanent fix to be expected for this?

Does the csproj file conversion to the new format apply to new projects created in VS2019?

Thanks.

@SabotageAndi
Copy link
Contributor

@ashafi1430 No, there is no permanent fix expected. And I don't think we can fix it.
CSProj migration is per project. If you create new projects, you have to choose the right project template to have the new format from the start.

@claudiotrinca
Copy link

claudiotrinca commented Mar 25, 2022

Hello everyone,
I have Microsoft Visual Studio Enterprise 2022 (64-bit) Version 17.0.6 Microsoft .Net Framework 4.8.04084
I am experiencing the same issue.
If I go on Test Explorer and execute F12 command on a test or right click and do "Go To Test"

image

I do not see the C# code of the specified test appear
I have tried above suggestions but unfortunately didn't work.

In the solution explore I have unloaded the project and inserted :
image

before It was just like this
image

Unfortunately nothing good happens when I reload the project. "Go To Test" functionality still doesn't work

@Hit8man8
Copy link

I ran into the same problem. I found that special characters in test naming cause this problem, e.g. >, ), (.
If you get rid of them in the naming, the problem disappears.
I know that this topic is old, but i hope this information will be helpful for someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests