mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use EXPECT_NEAR to improve test failure messages
Summary: The current test failures don't include the values passed to `EXPECT` which makes it difficult to understand if the test ended earlier or later then expected. ``` Failure: Value of: (commitDuration >= 1000 - threshold) && (commitDuration <= 1000 + threshold) Actual: false Expected: true ``` This diff uses the gtest `EXPECT_NEAR` to get exception messages including the delta: ``` Failure: The difference between telemetryDurationToMilliseconds(telemetry.getTextMeasureTime()) and 600 is 153, which exceeds threshold, where telemetryDurationToMilliseconds(telemetry.getTextMeasureTime()) evaluates to 753, 600 evaluates to 600, and threshold evaluates to 70. ``` This doesn't change the test's flakiness because of how sleep is implemented. Changelog: [Internal] Test only change Reviewed By: sammy-SC Differential Revision: D27595206 fbshipit-source-id: f31bdd92ecc7271c9491dda18639ea08820f5730
This commit is contained in:
1 parent
d29a7e7a89
commit
28ed660c2d
1 file changed
+5
-8
@@ -15,9 +15,6 @@
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
#define EXPECT_EQ_WITH_THRESHOLD(a, b, threshold) \
|
||||
EXPECT_TRUE((a >= b - threshold) && (a <= b + threshold))
|
||||
|
||||
template <typename ClockT>
|
||||
void sleep(double durationInSeconds) {
|
||||
auto timepoint = ClockT::now() +
|
||||
@@ -35,7 +32,7 @@ TEST(TransactionTelemetryTest, timepoints) {
|
||||
|
||||
auto duration = telemetryDurationToMilliseconds(timepointB - timepointA);
|
||||
|
||||
EXPECT_EQ_WITH_THRESHOLD(duration, 100, threshold);
|
||||
EXPECT_NEAR(duration, 100, threshold);
|
||||
}
|
||||
|
||||
TEST(TransactionTelemetryTest, normalUseCase) {
|
||||
@@ -82,12 +79,12 @@ TEST(TransactionTelemetryTest, normalUseCase) {
|
||||
auto mountDuration = telemetryDurationToMilliseconds(
|
||||
telemetry.getMountEndTime() - telemetry.getMountStartTime());
|
||||
|
||||
EXPECT_EQ_WITH_THRESHOLD(commitDuration, 1000, threshold);
|
||||
EXPECT_EQ_WITH_THRESHOLD(layoutDuration, 800, threshold);
|
||||
EXPECT_EQ_WITH_THRESHOLD(mountDuration, 100, threshold);
|
||||
EXPECT_NEAR(commitDuration, 1000, threshold);
|
||||
EXPECT_NEAR(layoutDuration, 800, threshold);
|
||||
EXPECT_NEAR(mountDuration, 100, threshold);
|
||||
|
||||
EXPECT_EQ(telemetry.getNumberOfTextMeasurements(), 3);
|
||||
EXPECT_EQ_WITH_THRESHOLD(
|
||||
EXPECT_NEAR(
|
||||
telemetryDurationToMilliseconds(telemetry.getTextMeasureTime()),
|
||||
600,
|
||||
threshold);
|
||||
|
||||
Reference in new issue
Block a user