Replace MSTest to VSTest to support Fakes

I’ve created a unit test using MS Fakes Framework. When I tried to run it from the build script, I’ve got an error:
Test method DateTimeHelperTests.ConvertServerTimeToTimeZoneTimeTest threw exception:
Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException: Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables.
The answer of told that instead of “using mstest.exe  I should have been using vstest.console.exe.”
There are a couple articles that explain the differences between MSTest and VSTest.console.exe.
I’ve created below table to describe parameters that should be changed if you move from MSTest to VSTest.
C:\Program Files (x86)\Microsoft Visual Studio 14\Common7\IDE\MSTest.exe
C:\Program Files (x86)\Microsoft Visual Studio 14\Common7\IDE\CommonExtensions\Microsoft\ TestWindow\VSTest.Console.exe
Full Path for typical installation
mstest /testcontainer:tests.dll
Vstest.console.exe myTestFile.dll myOtherTestFile.dll
Pass test.dll
TestResults\UserName_MachineName 2016-04-07 18_12_02.trx
/Settings:[file name] e.g.
mstest /testcontainer: “C:\TestProject2\myTestFile.dll” /testsettings:Local.TestSettings /category:!Broken /resultsfile:testResults.trx
vstest.console.exe  “C:\TestProject2\myTestFile.dll /Settings:Local.RunSettings /TestCaseFilter:”TestCategory=!Broken” /Logger:trx
Full example
<!– MSTest adapter –>
<MapInconclusiveToFailed>True </MapInconclusiveToFailed>
<DeleteDeploymentDirectoryAfterTestRunIsComplete> False </DeleteDeploymentDirectoryAfterTestRunIsComplete>
RunSettings for vstest.console adapter
/test:[test name]
to run multiple tests, use the /test option multiple times.
TestClass matches if the name Contains pattern
/Tests:[test name]
To provide multiple values, separate them by commas. Example: /Tests:TestMethod1,testMethod2
Classes and Methods matches if the name contains pattern
Also VSTest is running all tests in a single thread, so there is no proper isolation between tests and settings in one tests may effect subsequent tests.
I had to fix a few tests before the whole test project passed under VSTest.

#fakes, #unit-tests, #vstest

Global Convertion from MStest Assert to FluentAssertions

I found that FluentAssertions provide more descriptive logs in case of assertion failure.
However most of our test methods use MSTest Assert class.
For example statement
should  be changed to
They can be easily converted with the help of Visual Studio Replace. Just  select “use Regular Expressions”
For example
Search for:   \s*Assert.IsTrue\((.*)\);             replace to:      ($1).Should().BeTrue();
Search for:   \s*Assert.IsFalse\((.*)\);            replace to:      ($1).Should().BeFalse();
Search for:   \s*Assert.IsNotNull\((.*)\);        replace to:   ($1).Should().NotBeNull();
Search for:  (\s*)Assert.AreEqual\((.*),(.*)\);replace to:    $1($3).Should().Be($2);
I’ve used only most common asserts,that we are using,but they can be extended for other asserts.
Example of regular expression can be found on regex101

#fluentassertions, #regex, #unit-tests