CodeLens only finds tests that are written in MSTests

自作多情 提交于 2020-01-14 09:48:10

问题


I recently installed Visual Studio 2013 and CodeLens is amazing! The problem that I find is that whenever I open a class file that has methods in it, it doesn't seem to find the Unit Tests associated to the method if it is not written in MSTest. Is there anything that I have to do so that it can find other Unit tests like MSpec?

Is it because Machine Specifications has a different approach when creating unit tests vs MSTest or other testing framework out there?


回答1:


The tested by and test status indicators are powered by the test explorer.

So if your MSpec tests show up in the test explorer and are written in C# or VB, they should also show up in CodeLens.

(same answer as Visual Studio 2013 feature Code Lens with NUnit)

I just did it with NUnit on a clean machine by installing Nunit and the Nunit extension in extension manager. Here Main shows one reference and one passing test, and the test itself shows the checkmark after successfully running.




回答2:


I did the same thing that John Gardner showed in his answer, except I split it into 2 projects (to mimic the set up that I was working with in my real solution). At first it didn't work even though I could see the tests in Test Explorer. After a bit of searching, I stumbled onto the right answer for my situation.

It turns out that you need to:

(1) Create a new Unit Test Project (not a class library)

(2) Add NUnit reference to the Unit Test project (I used NuGet) and have the NUnit Test Adapter installed in VS2013

(3) Move your tests to this new project

(4) Once you save and build, now you can go back to your production code and see the "x/y passing" message and see the unit tests in the Test Explorer window.

Most of us that have been using NUnit for a long time are used to creating class libraries for our code instead of Unit Test Projects. It would be nice if the CodeLens documentation actually directly covered this (the documentation states "Test status indicators appear automatically in test projects" which was my clue).



来源:https://stackoverflow.com/questions/19548523/codelens-only-finds-tests-that-are-written-in-mstests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!