MSTest: CS0117 'Assert' does not contain a definition for 'ThrowsException'
22:46 15 Feb 2020

I'm writing some unit tests with MSTest, using C#, MSVS 2015 and .Net 4.6.1.

This line:

Assert.ThrowsException( () => 
  select.AllSelectedOptions[0]
);

Fails with this compile error:

CS0117 'Assert' does not contain a definition for 'ThrowsException'

My namespace is Microsoft.VisualStudio.TestTools.UnitTesting (the default when you create a unit test project in MSVS).

According to the documentation, Assert.ThrowsException(Action) should exist. But I don't see it in Intellisense ... and I'm getting the compile error.

I've tried a couple of different versions of MSVS (MSVS 2015 and MSVS 2019) and a couple of different versions of MSTest.

Q: Any ideas what might be wrong?


As Clint said below, I need to install MSTest v2 from NuGet in order to use Assert.ThrowsException() in MSVS 2015.

But after doing this, MSVS isn't finding any of my tests anymore:

MSVS > Test > Run All (or "Test > Debug > All Tests"):

------ Discover test started ------
========== Discover test finished: 0 found (0:00:01.127375) ==========

Any suggestions?

c# mstest vs-unit-testing-framework