This open-source Project hosted by Google, Http://code.google.com/p/googletest/ (gtest) It has been used in many other open-source projects of Google. For example, the advantage of chromium gtest is that the writing case is simple and cross-platform. It has certain scalability. Use the test macro to add our Code You can generate a case, for example, test (factorialtest, zero) {expect_eq (1, factorial (0);} Here factorialtest is the case name, zero is the test name expect_eq. This macro indicates that the expected values are equal. Here we expect the function factorial (INT) to be written. If the parameter is 0, 1 is returned. How can we execute this test case? Write the following code in the main function: int _ tmain (INT argc, _ tchar * argv []) {testing: initgoogletest (& argc, argv ); return run_all_tests ();} testing: initgoogletest (& argc, argv); this sentence is not necessary, but it is only necessary to pass the execution parameters to the test framework to run the test. Program , Gtest will show the detailed test process. Obviously, an expect_eq macro is not enough for us to use. gtest provides us with more judgment macros: the bool type has expect_true, expect_false numeric types include expect_eq, expect_ne, expect_lt, expect_le, expect_gt, and expect_ge strings with expect_streq, expect_strne, distinct, and distinct. If an exact CT _ * fails, the case will continue, if you want to stop, gtest provides a corresponding assert _ * for each of your CT _ * cases to forcibly return a successful result. If you want to call succeed (), otherwise, you only need to call fail (). If you want to add your own output during the test, you only need to add <"your output" to the macro of gtest. In addition to the simple check above, exception determination is also supported, because sometimes we return errors by exceptions. By inheriting testing: Environment and implementing setup and teardown, you can extend this test framework. In addition, there is a more complex test_f waiting for you. complexity means that the implementation is complicated, but the use is not complicated. Google provides us with a very good wheel. If you are interested, you can check the code of SVN Co gtest, which contains sample and Wik.
Other C ++ unit test tools include:
Cppunit (nunit for C #)
A tool that can make create C ++ test cases using nunit.