次の方法で共有


How to re-target unit-tests to .Net Framework 3.5 in VS 2010 SP1

Visual Studio 2010 Service Pack 1 enables basic support for unit tests that target .Net framework 3.5.  With this support the users can:

  • Create new unit-test projects and target them to the .NET Framework 3.5.
  • Upgrade VS 2008 unit-test projects to VS 2010 SP1 and then re-target them to .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 VS 2010 SP1 build agent as part of a build.

The capabilities listed above also enable developers to write unit tests, and integration tests for SharePoint 2010 applications using Visual Studio 2010 SP1.

The following walkthrough covers the steps required to re-target various unit-test projects to .Net Framework 3.5

C# unit-test projects

  • Go to Test-> New Test and create a new C# unit-test

         

  • Go to properties for the newly created project. The target Framework, by default is set to .Net Framework 4

       

  • Click on the drop down to select .Net Framework 3.5. Changing the selection will warn about requiring a reload of the project. Click yes and continue.

        

  • You can now run C# unit-tests that target .Net Framework 3.5.     
  • Note that enabling Diagnostic Data Adapters is not supported with tests that target .Net Framework 3.5. If you enable it the following warning will be shown in the test results.

            

 

C++/CLI Unit-test Projects

To build C++/CLI unit-test projects that target .Net Framework 3.5, VS 2008 SP1 must be installed along with VS 2010 SP1. The details and steps for this requirement are documented at https://blogs.msdn.com/b/visualstudio/archive/2009/11/22/framework-multi-targeting-for-vc-projects.aspx.

  • Once the required pre-requisites have been met, create a C++ unit-test project via Test->New Test
  •  Once the project is created, unload it and edit the .vcxproj file.

        

  • Set the TargetFrameworkVersion to v3.5 in the Property Group labeled "Globals"

       

  •  Save the file. The tests that target .Net Fwk 3.5 can now be run.

 

VB .Net Unit-test Projects

  • Create a new VB.Net unit-test project.

       

  • Go to Properties->Compile->Advanced Compile Options and change the target framework from .Net Framework 4.0 to .Net Framework 3.5.

           

 

Known Limitations

The following are the known limitations of the support we are enabling:

  • 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.

Please try out this feature in the SP1 Beta and let us know if you have feedback.

Abhishek Agrawal, Program Manager, Visual Studio

Comments

  • Anonymous
    December 19, 2010
    Iam a dotnet developer, i need to switch over my area to testing for that iam learning testing through internet. When i googled for it i got your msdn site. Into it i got this blog and red your post. This is what i needed for . My doubt in testing was almost clarified. Thanks to msdn blog team. The steps were very clear. Good keep it up and post more blogs in visual studio. godwinsblog.cdtech.in/.../type-or-namespace-name-web-does-not.html

  • Anonymous
    January 03, 2011
    The comment has been removed

  • Anonymous
    February 16, 2011
    I suggest trying Typemock Isolator for Sharepoint. Typemock makes<a href="www.typemock.com/isolatorpp-product-page">unit tests</a> easy for Sharepoint developers.

  • Anonymous
    February 16, 2011
    Sorry, the link to Typemock is: www.typemock.com/isolatorpp-product-page Isolator makes unit testing within visual studio for the .NET Framework easier.

  • Anonymous
    March 08, 2011
    Are private assessors supported? If yes. how?