In MSTest, How can I verify exact error message using [ExpectedException(typeof(ApplicationException))]

You can create your own ExpectedException attribute where you can Assert the message of the Exception that was thrown. Code namespace TestProject { public sealed class MyExpectedException : ExpectedExceptionBaseAttribute { private Type _expectedExceptionType; private string _expectedExceptionMessage; public MyExpectedException(Type expectedExceptionType) { _expectedExceptionType = expectedExceptionType; _expectedExceptionMessage = string.Empty; } public MyExpectedException(Type expectedExceptionType, string expectedExceptionMessage) { _expectedExceptionType = … Read more

Guidance for running tests using MSTest v1 in Visual Studio 2017 15.8.1

I was getting a similar issue running Xamarin.UITests and resolved it by installing the “NUnit 2 Test Adapter” Extension in Visual Studio. In Visual Studio 2017 you do this from Tools > > Extensions and Updates… > Online > Search “NUnit Adapter” > click the NUnit 2 Test Adapter then the Download button to install. … Read more

Explicitly call static constructor

As I found out today, the static constructor CAN be called directly: from another Stackoverflow post The other answers are excellent, but if you need to force a class constructor to run without having a reference to the type (ie. reflection), you can use: Type type = …; System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle); I had to add this code … Read more