Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between MSTest.TestAdapter vs MSTest.TestFramework and when do I need which one?

What is actualy the difference between MSTest.TestAdapter vs MSTest.TestFramework and when do I need which one?

In the NuGet descriptions you can read:

MSTest.TestAdapter

The adapter to discover and execute MSTest Framework based tests.

MSTest.TestFramework

This is MSTest V2, the evolution of Microsoft's Test Framework. + To discover and execute tests install MSTest.TestAdapter.


Well, not very helpful and I always install both because I'm never sure which one I should take. Strangely that in one of my test projects I only have the MSTest.TestFramework (I guess by accident) and ReSharper still can discover tests.

My questions about these packages are:

  • Do you really always need to install both of them?
  • Why does it work even without the TestAdapter?
  • What can I do with the TestFramework? When would I need this one?

The project page on GitHub doesn't help much either. The only link

You can read more about MSTest V2 here.

navigates to a page that only says how great and open-source it is but nothing specific about either of the packages.

like image 664
t3chb0t Avatar asked Nov 12 '17 12:11

t3chb0t


People also ask

What is MSTest used for?

MSTest is Microsoft's tool used to run tests of . NET applications (in particular, it can be used for unit testing). In TestComplete, you can integrate your MSTest tests to your test projects and run them as part of your automated testing process.


2 Answers

So Visual Studio uses a framework called Visual Studio Test Platform to load test adapters,

https://github.com/Microsoft/vstest

To discover or execute test cases, VSTest would call the test adapters based on your project configuration. (That's why NUnit/xUnit/MSTest all ask you to install a test adapter NuGet package to your unit testing projects). So MSTest.TestAdapter exists for that purposes.

MSTest.TestFramework itself implements the testing frameworks and its contracts. So you need to add a NuGet reference of it in order to write unit test cases and have them compiled. Only compiled projects along with the test adapter can then be consumed by Visual Studio.

So the final answer to your question would be "you usually need both".

The other answer from @Nkosi of course can be right if you don't ever plan to use Visual Studio. MSTest has its own command line runner, which can run your unit test project without the test adapter.

like image 52
Lex Li Avatar answered Oct 05 '22 23:10

Lex Li


Do you really always need to install both of them?

No. Why? (See below)

Why does it work even without the TestAdapter?

There are other adapters/runners out there that can recognize MSTest framework and that can also discover and run MSTest Framework tests.

What can I do with the TestFramework?

So in general a test framework is one used to create/author your tests while adapters/runners discover and exercise discovered tests.

When would I need this one?

There are multiple frameworks and adapters/runners and you use the one of your choosing.

like image 43
Nkosi Avatar answered Oct 06 '22 01:10

Nkosi