Buy Me a Coffee

Buy Me a Coffee!

Tuesday, February 21, 2017

Making MSTest work from a command line when test artifacts are involved

Last night I was messing around with incorporating code coverage tests into the DissectPECOFFBinary project and ran into an issue with tests passing in VS 2015 but failing at the command line with MSTest.  I thankfully found the answer in the blogosphere, kudos to Ryan Burnham and his post Loading External Files for Image Comparison using Specflow and MSTests which showed me the way.  Quick summary, add partial classes for your features and tack on DeploymentItem attributes pointing to the files you need to be copied.  A fully verbose version is as follows:
  1. Highlight the binary files, right click on them, and click Properties in the context menu
    Set artifacts to copy on build
  2. Set the Copy to Output Directory of the files to Copy Always
    Set Copy to Output Directory to Copy Always
  3. Update the solution by adding partial classes for each feature file with attributes
  4. Update the step files to fall back to the appropriate file path.  This has to be done because the copied file will be placed in the root of the folder in the TestResults directory created by MSTest.
Done.  MSTest now correctly works from the command line.

May your code compile fully optimized.