2013-07-31 25 views
12

Tôi sử dụng thử nghiệm tham số giá trị trong gtest. Ví dụ, nếu tôi viếtTôi có thể cung cấp tên tốt hơn cho các thử nghiệm tham số có giá trị trong gtest không?

INSTANTIATE_TEST_CASE_P(InstantiationName, 
        FooTest, 
        ::testing::Values("meeny", "miny", "moe")); 

sau đó trong đầu ra tôi thấy tên thử nghiệm như

InstantiationName/FooTest.DoesBlah/0 for "meeny" 
InstantiationName/FooTest.DoesBlah/1 for "miny" 
InstantiationName/FooTest.DoesBlah/2 for "moe" 

Có cách nào để làm cho những cái tên này có ý nghĩa hơn? Tôi muốn xem

InstantiationName/FooTest.DoesBlah/meeny 
InstantiationName/FooTest.DoesBlah/miny 
InstantiationName/FooTest.DoesBlah/moe 
+0

Ít nhất là nếu có lỗi, GTest đưa ra điều này: 'Test/FooTest.DoesBlah/0, trong đó GetParam() = (000000013F6F2C00 trỏ đến" meeny ")' – Lev

Trả lời

2

Hai cách: (http://osdir.com/ml/googletestframework/2011-09/msg00005.html)

1) Patch PrettyUnitTestPrinter hiện để in tên thử nghiệm; một cái gì đó như:

--- a/gtest-1.7.0/src/gtest.cc 
+++ b/gtest-1.7.0/src/gtest.cc 
@@ -2774,6 +2774,7 @@ void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) { 
void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) { 
    ColoredPrintf(COLOR_GREEN, "[ RUN  ] "); 
    PrintTestName(test_info.test_case_name(), test_info.name()); 
+ PrintFullTestCommentIfPresent(test_info); 
    printf("\n"); 
    fflush(stdout); 
} 

2) Viết một TestListener mới để in kết quả kiểm tra theo ý bạn muốn. (https://code.google.com/p/googletest/source/browse/trunk/samples/sample9_unittest.cc) GTest cho phép đăng ký một người nghe thử nghiệm mới (và bỏ đăng ký mặc định dựng sẵn), cho phép tùy chỉnh khá linh hoạt của đầu ra thử nghiệm. Xem liên kết cho mã ví dụ.

Các vấn đề liên quan