Visual C++ Production Code

Please note the following about the code you want to test, which is referred to here as production code.

Unmanaged. If your production code is unmanaged, it needs to be callable from a static library, an .obj file, or a DLL entry point. Class methods that are embedded inside an executable file or a DLL will not work because unmanaged Visual C++ does not offer the runtime discovery mechanism, reflection. Therefore, only the traditional native binding mechanisms will work.

Mixed. A mixed project is a project that uses the /clr compiler option. If your production code is mixed, and not an executable file, any callable method in your code can be called and tested.

Safe or Pure. If your production code is safe or pure, any callable assembly method can be called and tested, in an executable file or in a DLL.

Test Projects and Visual C++

Your test project has different capabilities depending on the compiler options you have set for the project. For more information, see Compiler Options and /clr (Common Language Runtime Compilation). The following sections describe the capabilities available for various compiler option settings.

Unmanaged

You cannot use unmanaged, or native, Visual C++ as the programming language for a test project.

Mixed

A mixed project is a project that uses the /clr compiler option. This kind of a test project provides the ability to test the following production code:

Static native libraries

Native DLL entry points

Standalone .obj files

Mixed-mode DLL assemblies with methods that are callable. This does not include executable files because they contain unmanaged code, and unmanaged executable code is generally not re-base address enabled.

Any managed method that is callable. This is code that is compiled with the /clr:pure or /clr:safe compiler option.

Safe or Pure

If you are using either the /clr:pure or the /clr:safe compiler option with your test project, it provides the ability to test any managed method that is callable. This means production code that is compiled with the /clr, /clr:pure, or /clr:safe compiler option.

Code Generation and Visual C++

You can generate unit tests into a Visual C++ test project. You can generate these tests from a Visual C++ production code project. Please note the following:

Production code project. If your production code is written in Visual C++, you can generate unit tests only if your product uses the /clr:safe compiler option.

Test project. Code generation can produce unit tests in any of the Visual C++ test project types: mixed, safe, and pure. The default project type produced is a /clr:safe project. If you want to change your project to /clr or /clr:pure, you do so at any time by using Visual C++ compiler options. For more information, see /clr (Common Language Runtime Compilation).