google / google/googletest

total_part_count() won't return success part count.

Open
#1,783 2 comments 0 reactions 1 assignee Claimed by @sbenzaquen View on GitHub
Dominant language
C++
Stars
39.5k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

Just as below test code, the expected total part count is 4, but actual is 0:
```
class MinimalistPrinter : public ::testing::EmptyTestEventListener {
// Called before a test starts.
virtual void OnTestStart(const ::testing::TestInfo& test_info) {
std::cout << "***TEST START:" << test_info.test_case_name()
<< "." << test_info.name() << std::endl;
}

// Called after a failed assertion or a SUCCESS().
virtual void OnTestPartResult(const ::testing::TestPartResult& test_part_result) {
printf("%s in %s:%d\n%s\n",
test_part_result.failed() ? "*** Failure" : "Success",
test_part_result.file_name(),
test_part_result.line_number(),
test_part_result.summary());
}

// Called after a test ends.
virtual void OnTestEnd(const ::testing::TestInfo& test_info) {
std::cout << "***TEST END:" << test_info.test_case_name()
<< "." << test_info.name() << std::endl;
std::cout << "Part Count:" << test_info.result()->total_part_count() << std::endl;
}
};

int add_one(int a) {
return a + 1;
}

TEST(TestCase1, check_function) {
EXPECT_EQ(4, add_one(3));
EXPECT_EQ(4, add_one(3));
EXPECT_EQ(4, add_one(3));
EXPECT_EQ(4, add_one(3));
}

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
// Gets hold of the event listener list.
::testing::TestEventListeners& listeners =
::testing::UnitTest::GetInstance()->listeners();
// Adds a listener to the end. googletest takes the ownership.
delete listeners.Release(listeners.default_result_printer());
listeners.Append(new MinimalistPrinter);
return RUN_ALL_TESTS();
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.