It is intended for people who are using CUnit as a unit testing framework. ・ People who want to recommend Google Test to their surroundings ・ People who want to explain the usefulness to the people concerned because they want to switch to Google Test
It is intended for people who are looking for a test framework that is easier to use than CUnit, but I think the content is thin compared to other pages. I know Google Test to some extent and focus on how to recommend it to others.
I think it would be better to have a sample code, but I will upload it if there is a need.
Google Test, like CUnit, is a unit testing framework. All the manuals are available online (though I think CUnit also has ones for this). http://opencv.jp/googletestdocs/primer.html
I have downloaded and used 1.8.0 from here. https://github.com/google/googletest/releases
I have listed them in the order in which they are most effective from the developer's perspective. If you explain in this order, you will surely want to use it. Also, when explaining the usefulness to people other than developers, the point that "can be written short" from the perspective of the project manager is the man-hours for test maintenance, and the point that "installation is unnecessary" from the perspective of the environment manager is insisted. May be a benefit. We will also touch on the utilization of existing CUnit assets at the end of this page.
・ (Maybe) Can be written shorter than CUnit ・ I wrote a test case but never forgot to put it in ・ Can be used without installation ・ No main function required ・ A list of test cases can be output. ・ Only specified tests can be executed ・ Setup and TearDown functions can be prepared for each test suite (strictly called test fixture). -The disabled test will explicitly display "How many tests have been disabled" when the test is executed.
The following will be explained in order.
CUnit needs to add AddSuite-like processing after writing a test case, It's easy to make the mistake of writing it inadvertently but not testing it. Google Test will automatically include a test case in the test when you write it.
It provides all CPP files and headers, so if you include the include path settings and CPP in the build target, you can use it without installing it in / usr / local / lib. Useful when you want to give it a try and recommend it. The detailed method is mentioned in this article (http://d.hatena.ne.jp/E_Mattsan/20120215/1329311774) etc., but used-src is not currently included in the Release version, so the following is implemented I had to.
fuse_gtest_files.py
Of course, you can also install and use it.
Since Google Test has prepared it, you can use it just by including it in the build target.
See below for details. http://opencv.jp/googletestdocs/advancedguide.html#adv-listing-test-names http://opencv.jp/googletestdocs/advancedguide.html#adv-running-a-subset-of-the-tests
In CUnit, I have experience of partially #if 0 and cluttering where test cases are defined.
See below for details. http://opencv.jp/googletestdocs/primer.html#primer-test-fixtures
What test cases in this test suite should be initialized first and what should be cleaned up? I think that readability will be improved because you can write that in the declaration of the test suite.
See below for details. http://opencv.jp/googletestdocs/advancedguide.html#adv-temporarily-disabling-tests
If it is #if 0, it may be forgotten someday. However, in the case of "It will be NG because it is not implemented now. But I have made a test for the time being, so I want to test it once it is implemented" I think it's a good idea to set it to "explicit invalidation test".
Requires knowledge of C ++, but only the ability to define classes and super rudimentary knowledge of extern "C". I can't think of any disadvantages with CUnit.
-Need to specify -lpthread -I have built the cpp source with gcc instead of g ++
There seem to be various useful functions, but if the developer uses them too freely, tricky tests will be created or it will be out of control, so I think it is good to decide which functions should be used and which should not be used.
What happens to test cases written in CUnit after migrating to Google Test? Do you throw it away? I think that the question will always be asked by the manager. From the conclusion, it is impossible to divert it with zero man-hours, but it can be used with a little mechanical modification. If you continue to make tests in the future, you can explain that it is an investment that can be recovered by the amount of increased production efficiency.
Some modifications need to be made to the CUnit-based test cases. I will write in detail if there is a need, but make a note of what I did.
Delete or disable the main function, AddSuite, AddTestCase processing, etc.
void testcase01(void){
To
TEST(testcase01){
Or
TEST_F(testName, testcase01){
This will be overloaded depending on the number of test cases. It's a mechanical work, so it seems that you can do it with a script etc., but if you can not devote to this replacement work, please give up ...
#define CU_ASSERT EXPECT_TRUE
#include "testCaseForCUnit.c"
For Google Test.
I wrote it while thinking that there was no need for it, so I think there are some points that are difficult to understand. Give me a sample code! I will update it if there is something like that. Please forgive me for the first post ...
Recommended Posts