Use Visual Studio for unit testing and visual Unit Testing
I. Suggestions on using Visual Studio for unit testing
1. write unit tests first (in my opinion, it should be the interface first, if any)-> test failure-> with minimal changes (that is, write the actual code) make the test pass (but in VS2012 it is no longer possible to generate the test project directly through the existing project. I think this function should be retained. Microsoft is always like this, forcing users to adapt to their products, but have to adapt );
2. Do not append the function (CODE) due to unit test, that is, the logic is not affected by unit test;
3. Changed the logic of the Code (add, delete, modify), and the unit test should be run in time;
4. Declare Attribute -- TestCategory ("classification or feature name") in the test method ");
5. Add the Fakes assembly in the unit test project to separate external dependencies (such as database access and configuration information retrieval );
6. initialize the members and other information in the unit test class. You can add methods and declare Attribute [TestInitialize] (the method must be public );
II. The following uses VS2012 as an example to illustrate how to perform unit testing in Visual Studio.
1. Right-click Solution to bring up the Context menu)
Select Add-New Project. In the template, select Visual C #-Test-Unit Test Project.
2. Obtain the template.
3. Add the code to be tested in the Test method (TestMethod1 is the default TestMethod1 here, which is generally changed to the method name to be tested + Test ).
For example, to add the XmlSerializationTest class, the Code is as follows:
C # code Replication
[TestClass]
public class XmlSerializationTest
{
private XmlSerialization serialization;
[TestInitialize]
public void InitTest ()
{
this.serialization = new XmlSerialization (@ "F: \\ usermodel.seri");
}
[TestMethod]
public void TestWriteXml ()
{
UserModel user = new UserModel ();
bool flag = serialization.WriteXml <UserModel> (user);
Assert.IsTrue (flag);
Assert.IsFalse (serialization.WriteXml <UserModel> (null));
}
[TestMethod]
public void TestReadXml ()
{
UserModel user = new UserModel ();
user.LoginName = "aa";
serialization.WriteXml <UserModel> (user);
UserModel model = serialization.ReadXml <UserModel> ();
Assert.IsNotNull (model);
Assert.AreEqual (user.LoginName, model.LoginName);
// The path does not exist, it should return null
UserModel modelnull = serialization.ReadXml <UserModel> (@ "F: \\ notexists.seri");
Assert.IsNull (modelnull);
}
}
4. After writing the Test code, you can click Test-Run-AllTests in the top menu to perform the Test.
After the test is completed. The result list is displayed below. The red color indicates the TestCase that fails. To DEBUG it, right-click the red TestCase and select Debug selected Tests. After modification, you can also right-click the TestCase you want to re-test and select Run Selected Tests.
How to use visual studio2008 for unit test video
I will help you ask my friends later. I really don't know.
Currently, visual studio 2010 is used for programming. What test tool is best for testing C ++ code unit testing? How to configure it? Plus points if you are satisfied
1. Get the Cppunit release and download the cppunit-1.10.2
2.use install-win32.txt,
3. view the example in examples and view its configuration.
Libraries :----------
All the compiled libraries and DLL can be found in the 'lib' directory. Most libraries can be built from src/CppUnitLibraries. dsw workspace.
Lib \:
Cppunit. lib: CppUnit static library "Multithreaded DLL"
Cppunitd. lib: CppUnit static library "Debug Multithreaded DLL"
Cppunit_dll.dll: CppUnit dynamic library (DLL) "Multithreaded DLL"
Cppunit_dll.lib: CppUnit dynamic import library "Multithreaded DLL"
Cppunitd_dll.dll: CppUnit dynamic library (DLL) "Debug Multithreaded DLL"
Cppunitd_dll.lib: CppUnit dynamic import library "Debug Multithreaded DLL"
Qttestrunner. dll: QT TestRunner dynamic library (DLL) "Multithreaded DLL"
Qttestrunner. lib: QT TestRunner import library "Multithreaded DLL"
Testrunner. dll: MFC TestRunner dynamic library (DLL) "Multithreaded DLL"
Testrunner. lib: MFC TestRunner import library "Multithreaded DLL"
Testrunnerd. dll: MFC TestRunner dynamic library (DLL) "Debug Multithreaded DLL"
Testrunnerd. lib: MFC TestRunner import library "Debug Multithreaded DLL"
Testrunneru. dll: MFC Unicode TestRunner dynamic library (DLL) "Multithreaded DLL"
Testrunneru. lib: MFC Unicode TestRunner import library "Multithreaded DLL"
Testrunnerud. dll: MFC Unicode TestRunner dynamic library (DLL) "Debug Multithreade... full text>