VS2010 SP1 New Features: Unit Tests for Framework 3.5

Versions: 2010 SP1

Code: vstipDebug0041

 

If you haven’t heard yet, you now have “basic support for unit tests that target the .NET Framework 3.5” in VS2010 with SP1.  There are a lot of reasons for adding this functionality but the main reason for putting it in is to support doing unit tests for your SharePoint 2010 projects.  The service pack documentation refers to Amit Chatterjee's blog post for more information.  Here is the link to the post:

https://blogs.msdn.com/b/amit_chatterjee/archive/2010/12/10/visual-studio-2010-service-pack-1-beta-released-information-on-test-and-lab-management-changes.aspx

 

Essentially, you are able to do the following:

  • Create new unit test projects and target them to the .NET Framework 3.5.
  • Run unit tests that target the .NET Framework 3.5 from Visual Studio 2010 SP1 on your local machine.
  • Run unit tests that target the .NET Framework 3.5 using mstest.exe from the command prompt.
  • Run unit tests on a build agent as part of a build.

 

Here are the known limitations:

  • The default target framework in test projects is the .NET Framework 4. If you upgrade test projects from Visual Studio 2008, they will be upgraded to target the .NET Framework 4 by default. You can edit the project properties and explicitly re-target the project to the .NET Framework 3.5.
  • In the .NET Framework 3.5, multi-targeting is supported for test projects that contain only unit tests. The .NET Framework 3.5 does not support any other test type, such as coded UI or load test. The re-targeting is blocked for test types other than unit tests.
  • Execution of .NET Framework 3.5 tests is supported only in the default host adapter. It is not supported using the ASP.NET host adapter. ASP.NET applications that have to run in ASP.NET development server context must be .NET Framework 4-compatible.
  • Data collection support is disabled when you execute tests that support .NET Framework 3.5 multi-targeting. You can run code coverage using the Visual Studio command line tools.
  • Unit tests using the .NET Framework 3.5 unit tests cannot run on a remote machine.

 

 

Now let me show you how you would go about making .NET 3.5 unit tests:

 

VB

For Visual Basic it’s pretty easy.  Just bring up the Add New Project dialog (CTRL + SHIFT + N) and change the Framework to 3.5:

image

 

Now go to the Test template area and select the Test Project then click OK:

image

 

You will now have a Framework 3.5 test project.  You can verify this by going into the project properties, Compile tab, Advanced Compile Options:

image

 

You can also change a 4.0 Framework test project to 3.5 by going to this same location as well.

 

 

C#

In C# there is no test project template for the Framework 3.5 so you have to first create a 4.0 Test Project:

image

 

Then you go into the project properties, Application tab, Target Framework and change the version to 3.5:

image

 

You will get the typical warning message, just click Yes:

image

 

You will now have a Unit test that targets the 3.5 Framework.  You can go back to project properties, Application tab, Target Framework and verify the change:

image

 

You are now ready to start writing tests that target the 3.5 Framework.