diff options
author | Geir Storli <geirst@verizonmedia.com> | 2019-02-18 12:06:43 +0000 |
---|---|---|
committer | Geir Storli <geirst@verizonmedia.com> | 2019-02-18 13:37:11 +0000 |
commit | 967cf73255ec1495c5a7bf8070992aa8781ff158 (patch) | |
tree | ecf0c3e8f15f9430b82cfd8b7686745b405b22ee /metrics | |
parent | f82f1cec65c02aff71039127ac361657e70ce06b (diff) |
Add gtest runner in metrics and migrate countmetrictest from CppUnit to gtest.
Diffstat (limited to 'metrics')
-rw-r--r-- | metrics/src/tests/.gitignore | 1 | ||||
-rw-r--r-- | metrics/src/tests/CMakeLists.txt | 21 | ||||
-rw-r--r-- | metrics/src/tests/countmetrictest.cpp | 37 | ||||
-rw-r--r-- | metrics/src/tests/gtest_runner.cpp | 14 |
4 files changed, 48 insertions, 25 deletions
diff --git a/metrics/src/tests/.gitignore b/metrics/src/tests/.gitignore index 453dd9e4ab3..81504ca2f86 100644 --- a/metrics/src/tests/.gitignore +++ b/metrics/src/tests/.gitignore @@ -4,4 +4,5 @@ Makefile testrunner /test.vlog +metrics_gtest_runner_app metrics_testrunner_app diff --git a/metrics/src/tests/CMakeLists.txt b/metrics/src/tests/CMakeLists.txt index af13bd2ce0b..691b1a618b0 100644 --- a/metrics/src/tests/CMakeLists.txt +++ b/metrics/src/tests/CMakeLists.txt @@ -1,8 +1,27 @@ # Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +# Runner for unit tests written in gtest. +# NOTE: All new test classes should be added here. +vespa_add_executable(metrics_gtest_runner_app TEST + SOURCES + countmetrictest.cpp + gtest_runner.cpp + DEPENDS + metrics + vdstestlib + gtest +) + +vespa_add_test( + NAME metrics_gtest_runner_app + COMMAND metrics_gtest_runner_app + DEPENDS metrics_gtest_runner_app +) + +# Runner for unit tests written in CppUnit (DEPRECATED). vespa_add_executable(metrics_testrunner_app TEST SOURCES testrunner.cpp - countmetrictest.cpp valuemetrictest.cpp metricsettest.cpp summetrictest.cpp diff --git a/metrics/src/tests/countmetrictest.cpp b/metrics/src/tests/countmetrictest.cpp index af94f78dfdf..3add1f78861 100644 --- a/metrics/src/tests/countmetrictest.cpp +++ b/metrics/src/tests/countmetrictest.cpp @@ -1,53 +1,42 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/vespalib/objects/floatingpointtype.h> #include <vespa/metrics/countmetric.h> +#include <gtest/gtest.h> using vespalib::Double; namespace metrics { -struct CountMetricTest : public CppUnit::TestFixture { - void testLongCountMetric(); - - CPPUNIT_TEST_SUITE(CountMetricTest); - CPPUNIT_TEST(testLongCountMetric); - CPPUNIT_TEST_SUITE_END(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(CountMetricTest); - -void CountMetricTest::testLongCountMetric() +TEST(CountMetricTest, testLongCountMetric) { LongCountMetric m("test", {{"tag"}}, "description"); m.set(100); - CPPUNIT_ASSERT_EQUAL(uint64_t(100), m.getValue()); + EXPECT_EQ(uint64_t(100), m.getValue()); m.inc(5); - CPPUNIT_ASSERT_EQUAL(uint64_t(105), m.getValue()); + EXPECT_EQ(uint64_t(105), m.getValue()); m.dec(15); - CPPUNIT_ASSERT_EQUAL(uint64_t(90), m.getValue()); + EXPECT_EQ(uint64_t(90), m.getValue()); LongCountMetric m2(m); - CPPUNIT_ASSERT_EQUAL(uint64_t(90), m2.getValue()); + EXPECT_EQ(uint64_t(90), m2.getValue()); m.reset(); - CPPUNIT_ASSERT_EQUAL(uint64_t(0), m.getValue()); + EXPECT_EQ(uint64_t(0), m.getValue()); LongCountMetric n("m2", {}, "desc"); n.set(6); - CPPUNIT_ASSERT_EQUAL(uint64_t(6), n.getValue()); + EXPECT_EQ(uint64_t(6), n.getValue()); LongCountMetric o = m2 + n; - CPPUNIT_ASSERT_EQUAL(uint64_t(96), o.getValue()); + EXPECT_EQ(uint64_t(96), o.getValue()); o = m2 - n; - CPPUNIT_ASSERT_EQUAL(uint64_t(84), o.getValue()); + EXPECT_EQ(uint64_t(84), o.getValue()); std::string expected("test count=84"); - CPPUNIT_ASSERT_EQUAL(expected, o.toString()); + EXPECT_EQ(expected, o.toString()); - CPPUNIT_ASSERT_EQUAL(Double(84), Double(o.getDoubleValue("value"))); - CPPUNIT_ASSERT_EQUAL(int64_t(84), o.getLongValue("value")); -// (void) expected; + EXPECT_EQ(Double(84), Double(o.getDoubleValue("value"))); + EXPECT_EQ(int64_t(84), o.getLongValue("value")); } } diff --git a/metrics/src/tests/gtest_runner.cpp b/metrics/src/tests/gtest_runner.cpp new file mode 100644 index 00000000000..35475ba19a9 --- /dev/null +++ b/metrics/src/tests/gtest_runner.cpp @@ -0,0 +1,14 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <gtest/gtest.h> + +#include <vespa/log/log.h> +LOG_SETUP("metrics_gtest_runner"); + +int +main(int argc, char* argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + |