主ç«ã£ãå®è¡æãªãã·ã§ã³ã«ã¤ãã¦èª¬æãã¾ãã
å®è¡æãªãã·ã§ã³ã«ã¯ï¼--gtest_list_tests
ãã®ããã¦ï¼å¯¾å¿ããç°å¢å¤æ°ãããã¾ããç°å¢å¤æ°ã«å¤ãè¨å®ãã¦ããã¨ãå®è¡æãªãã·ã§ã³ãæå®ããã¨ãã¨åãå¹æãå¾ããã¾ãã
ãªãã·ã§ã³ | ç°å¢å¤æ° | æ©è½ |
---|---|---|
--gtest_list_tests | ãã¹ãã®ä¸è¦§ã表示ãã | |
--gtest_filter | GTEST_FILTER | å®è¡ãããã¹ããæå®ããï¼ãã£ã«ã¿ãªã³ã°ããï¼ |
--gtest_repeat | GTEST_REPEAT | ãã¹ããç¹°ãè¿ãåæ°ãæå®ãã |
--gtest_break_on_failure | GTEST_BREAK_ON_FAILURE | ãã¹ãã失æããæç¹ã§ãã¹ãå ¨ä½ãä¸æããã |
--gtest_color | GTEST_COLOR | çµæã®ã«ã©ã¼è¡¨ç¤ºãæå®ãã |
--gtest_print_time | GTEST_PRINT_TIME | ãã¹ãã®å®è¡æéã表示ãã |
--gtest_output | GTEST_OUTPUT | çµæã®åºåå½¢å¼ãæå®ãã |
以ä¸ã次ã®ã³ã¼ããä¾ã«èª¬æãã¾ãã
#include <gtest/gtest.h> int add(int lhs, int rhs) { return lhs + rhs; } int mul(int lhs, int rhs) { return lhs * rhs; } TEST(AddTest, Test1) { ASSERT_EQ(2, add(1, 1)); } TEST(AddTest, Test2) { ASSERT_EQ(2, add(-1, -1)); } TEST(MulTest, Test1) { ASSERT_EQ(1, mul(1, 1)); } TEST(MulTest, Test2) { ASSERT_EQ(1, mul(-1, -1)); } int main(int argc, char* argv[]) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }
å®è¡çµæã
[==========] Running 4 tests from 2 test cases. [----------] Global test environment set-up. [----------] 2 tests from AddTest [ RUN ] AddTest.Test1 [ OK ] AddTest.Test1 [ RUN ] AddTest.Test2 ex8.cpp:20: Failure Value of: add(-1, -1) Actual: -2 Expected: 2 [ FAILED ] AddTest.Test2 [----------] 2 tests from MulTest [ RUN ] MulTest.Test1 [ OK ] MulTest.Test1 [ RUN ] MulTest.Test2 [ OK ] MulTest.Test2 [----------] Global test environment tear-down [==========] 4 tests from 2 test cases ran. [ PASSED ] 3 tests. [ FAILED ] 1 test, listed below: [ FAILED ] AddTest.Test2 1 FAILED TEST
--gtest_list_tests
ãã¹ãã®ä¸è¦§ã表示ãã¾ãããã¹ãã®å®è¡ã¯ãããªããã¾ããã
AddTest. Test1 Test2 MulTest. Test1 Test2
--gtest_filter
å®è¡ãããã¹ããæå®ãã¾ãã
ãã¹ãã±ã¼ã¹åããã¹ãåãæå®ãããã¨ã§ãä¸é¨ã®ãã¹ãã®ã¿ãå®è¡ãããã¨ãã§ãã¾ãã
ã¾ãååã®æå®ã§ã¯ãã¯ã¤ã«ãã«ã¼ãï¼*
ï¼ã使ããã¨ãã§ãã¾ãã
ãªãã·ã§ã³ã®æå®ä¾ | å®è¡ããããã¹ã |
---|---|
--gtest_filter=AddTest.* |
ãã¹ãã±ã¼ã¹åãAddTest ã®ãã¹ãã®ã¿å®è¡ãã |
--gtest_filter=*.Test1 |
ãã¹ãåãTest1 ã®ãã¹ãã®ã¿å®è¡ãã |
--gtest_filter=*Test.Test1 |
ãã¹ãã±ã¼ã¹åã*Test ããã¹ãåãTest1 ã®ãã¹ãã®ã¿å®è¡ãã |
--gtest_filter=AddTest.Test* |
ãã¹ãã±ã¼ã¹åãAddTest ããã¹ãåãTest* ã®ãã¹ãã®ã¿å®è¡ãã |
--gtest_filter=-*.Test1 |
ãã¹ãåãTest1 ã®ãã¹ã以å¤ã®ãã¹ãã®ã¿å®è¡ãã |
--gtest_filter=AddTest.*-AddTest.Test1 |
ãã¹ãã±ã¼ã¹åãAddTest ã§AddTest.Test1 ãé¤ãããã¹ãã®ã¿å®è¡ãã |
--gtest_repeat
ãã¹ããå®è¡ããåæ°ãæå®ãã¾ãã
è² æ°ãæå®ããå ´åããã¹ãã¯ç¹°ãè¿ãå®è¡ããåæ¢ãã¾ããã
ãªãã·ã§ã³ã®æå®ä¾ | å®è¡ããããã¹ã |
---|---|
--gtest_repeat=2 |
ãã¹ãã¯ï¼åå®è¡ããã |
--gtest_repeat=-1 |
ãã¹ãã¯åæ¢ãããã¾ã§ç¹°ãè¿ãå®è¡ããã |
--gtest_break_on_failure
ãã¹ãã失æããããã¨ãããã¹ãã¹ã¤ã¼ãå
¨ä½ãä¸æããã¾ãã
ASSERT_*
ãã¯ãã失æããå ´åã§ãããã¹ããä¸æããã ãã§ãã¹ãã±ã¼ã¹ããã¹ãã¹ã¤ã¼ãå
¨ä½ã¯åæ¢ããã次ã®ãã¹ããå®è¡ããã¾ãã
ãã®ãªãã·ã§ã³ãæå®ããã¨ããã¹ãã失æããæç¹ã§ãã¹ãã¹ã¤ã¼ãå
¨ä½ãä¸æãããã¹ããåæ¢ããã¾ãã
ãã®ãªãã·ã§ã³ã¯--gtest_repeat
ã«è² æ°ãæå®ããå ´åã«ãæå¹ã§ãç¹°ãè¿ãã®ä¸ã§ãã¹ãã失æããã¨ãã«ç¹°ãè¿ããä¸æããã¾ãã
--gtest_color
ã«ã©ã¼è¡¨ç¤ºãæå®ãã¾ãã
--gtest_color=yes
ããããã¯--gtest_color=1
ã¨æå®ããã¨ããã¹ãçµæãè²ä»ãããã¾ãã
--gtest_color=yes
ãæå®ããã¨ãã®å®è¡çµæã
[==========] Running 4 tests from 2 test cases. [----------] Global test environment set-up. [----------] 2 tests from AddTest [ RUN ] AddTest.Test1 [ OK ] AddTest.Test1 [ RUN ] AddTest.Test2 ex8.cpp:20: Failure Value of: add(-1, -1) Actual: -2 Expected: 2 [ FAILED ] AddTest.Test2 [----------] 2 tests from MulTest [ RUN ] MulTest.Test1 [ OK ] MulTest.Test1 [ RUN ] MulTest.Test2 [ OK ] MulTest.Test2 [----------] Global test environment tear-down [==========] 4 tests from 2 test cases ran. [ PASSED ] 3 tests. [ FAILED ] 1 test, listed below: [ FAILED ] AddTest.Test2 1 FAILED TEST
--gtest_print_time
ãã¹ãã®å®è¡æéã表示ãã¾ãã
--gtest_print_time
ãæå®ããã¨ãã®å®è¡çµæã
[==========] Running 4 tests from 2 test cases. [----------] Global test environment set-up. [----------] 2 tests from AddTest [ RUN ] AddTest.Test1 [ OK ] AddTest.Test1 (0 ms) [ RUN ] AddTest.Test2 ex8.cpp:20: Failure Value of: add(-1, -1) Actual: -2 Expected: 2 [ FAILED ] AddTest.Test2 (30 ms) [----------] 2 tests from AddTest (31 ms total) [----------] 2 tests from MulTest [ RUN ] MulTest.Test1 [ OK ] MulTest.Test1 (0 ms) [ RUN ] MulTest.Test2 [ OK ] MulTest.Test2 (0 ms) [----------] 2 tests from MulTest (32 ms total) [----------] Global test environment tear-down [==========] 4 tests from 2 test cases ran. (67 ms total) [ PASSED ] 3 tests. [ FAILED ] 1 test, listed below: [ FAILED ] AddTest.Test2 1 FAILED TEST
--gtest_output
ãã¹ãçµæãæå®ããå½¢å¼ã§ãã¡ã¤ã«ã«åºåãã¾ãï¼ç¾æç¹ã§ã¯XMLå½¢å¼ã®ã¿ã®ãµãã¼ãã®ããã§ãï¼ã
--gtest_output="xml"
ã¨æå®ãã¦å®è¡ããå ´åãtest_detail.xmlã¨ãããã¡ã¤ã«åã®XMLãã¡ã¤ã«ãçæããã¾ãã
--gtest_output="xml:ãã¡ã¤ã«å"
ã¨æå®ãã¦å®è¡ããå ´åãæå®ãããã¡ã¤ã«åã®XMLãã¡ã¤ã«ãçæããã¾ãã
--gtest_output="xml:result.xml"
ãæå®ããã¨ãã®result.xmlãã¡ã¤ã«ã®å
容ã
<?xml version="1.0" encoding="UTF-8"?> <testsuite tests="4" failures="1" disabled="0" errors="0" time="44" name="AllTests"> <testsuite name="AddTest" tests="2" failures="1" disabled="0" errors="0" time="1"> <testcase name="Test1" status="run" time="0" classname="AddTest" /> <testcase name="Test2" status="run" time="1" classname="AddTest"> <failure message="ex8.cpp:20
Value of: add(-1, -1)
 Actual: -2
Expected: 2" type=""/> </testcase> </testsuite> <testsuite name="MulTest" tests="2" failures="0" disabled="0" errors="0" time="41"> <testcase name="Test1" status="run" time="0" classname="MulTest" /> <testcase name="Test2" status="run" time="0" classname="MulTest" /> </testsuite> </testsuite>