Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create a unit test assembly for a .NET Portable Class Library?

I am attempting to unit test a Portable Class Library that I've created and I want to make sure it's being tested with the same framework subset that it targets.

Per the Visual Studio ALM + Team Foundation Server blog, the MSTest unit test framework was converted to a PCL in Visual Studio 2012 RC; however, I am unable to create a portable class library and then reference the MSTest framework in VS2012 RTM.

  • Browsing in the "References" dialog shows me that no unit testing components are registered as compatible with PCL.
  • Adding a manual GAC reference in the project file to Microsoft.VisualStudio.QualityTools.UnitTestFramework yields a reference not found build error.
  • Adding a manual direct assembly reference to C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ReferenceAssemblies\v4.0\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll yields a build warning saying the UnitTestFramework assembly references an incompatible mscorlib version.

I did find (thanks to an early answer) that there is a project type Unit Test Library (Windows Store apps) that references a different MSTest assembly at C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0\ExtensionSDKs\MSTestFramework\11.0\References\CommonConfiguration\neutral\Microsoft.VisualStudio.TestPlatform.UnitTestFramework.dll. This project type creates a small no-UI Windows Store app... complete with manifest and everything. It also doesn't allow me to specify which frameworks I'm targeting - it appears to be only for Windows Store apps.

Under the potentially faulty assumption that I should be testing my Portable Class Library projects with unit test assemblies that target the same framework subset as the library-under-test...

How do I create a unit test assembly for a .NET Portable Class Library?

(I am open to other frameworks that also target PCL, I'm just currently unaware of other solutions besides MSTest that have taken this into account.)

like image 420
Travis Illig Avatar asked Oct 01 '12 16:10

Travis Illig


People also ask

How do I test a .NET class library?

Test the Release version of the libraryIn the Visual Studio toolbar, change the build configuration from Debug to Release. In Solution Explorer, right-click the StringLibrary project and select Build from the context menu to recompile the library. Run the unit tests by choosing Test Run > All Tests from the menu bar.

How do you create a unit test class?

To get started, select a method, a type, or a namespace in the code editor in the project you want to test, right-click, and then choose Create Unit Tests. The Create Unit Tests dialog opens where you can configure how you want the tests to be created.


1 Answers

xUnit now has support for PCL unit testing; http://xunit.github.io/

like image 134
noocyte Avatar answered Oct 10 '22 12:10

noocyte