C++ Testing Framework Catchã®ç´¹ä»
Catchã¨ã¯C++ã®ãã¹ãã£ã³ã°ã¬ã¼ã ã¯ã¼ã¯ã®1ã¤ã§ããããããªã³ãªã¼ã§ä½¿ããã¨ãåºæ¥ã¾ãï¼ç°¡åï¼
https://github.com/philsquared/Catch
ç§ã¯ãã¡ãã®ããã°ãæè¦ãã¦ç¥ãã¾ããã
ããã°ãºã: C++ Testing Framework ã® Catch ã使ã£ã¦ã¿ã
Google Testãªã©ã¨åãããã«JUnitå½¢å¼ã®xmlãåºåãããã¨ãã§ããã®ã§Jenkinsã§CIãããã¨ãå¯è½ã§ãã
触ã£ã¦ã¿ã¦ç§ãæããCatchã®è¯ãæã¯ã
- æ§é åãã¹ããã¨ã¦ãæ¸ãããã
- JUnit4ã©ã¤ã¯ãªassertThatã¨(ã«ã¹ã¿ã )Matcherããã
- ãã¹ãã±ã¼ã¹åãæååãªã®ã§æ¥æ¬èªåãä»ãããã
- ã¿ã°ãä»ããã®ãç°¡åã§ãã¿ã°ãéå®ãããã¹ãã®å®è¡ã容æ
ã¾ã ããåãã£ã¦ããªãã¨ããã¨æ°ã«ãªãã¨ãã
- ãã©ã¡ã¼ã¿åãåãã©ã¡ã¼ã¿åãã¹ãã¯æ¸ããã®ããæ¸ããã®ãªãæ¸ããããã®ã
- 製ä½ä¸ã®ããããMatcherã®æ°ãå°ãªã
- ããã¥ã¡ã³ããæä½éããç¡ã
ç§ã¯ä»Catchã趣å³ããã°ã©ãã³ã°ã§è©¦ç¨ãã¦ãã¾ãã
ãæè¿JUnit4ãåå¼·ãã¾ãã¦ãã¢ããã¼ã·ã§ã³ããªãã¬ã¯ã·ã§ã³ãæ´»ããããã¹ãã£ã³ã°ãã¬ã¼ã ã¯ã¼ã¯ã§ã¨ã¦ã便å©ã ã¨æãã¦ãã¾ãããJUnitã§ã¯ãã¹ãã¡ã½ããåã«æ¥æ¬èªã使ãæ
£ç¿ãããããã§ããç§ã¯JUnitã§æ§é åãã¹ãããã©ã¡ã¼ã¿åãã¹ããã«ã¼ã«ãassertThatã¨Matcherãªã©ãã¨ã¦ã便å©ã«æãã¾ããã
ãCatchã¯Fixtureãxmlã¬ãã¼ããããã¾ããããããã¯Google Testãªã©ã«ãããã¾ãããã¹ãã±ã¼ã¹ã«æ¥æ¬èªãã¤ãããã¨ãåºæ¥ããassertThatããããã¨ãJunitæèãã¦ãã®ããªã¨æãã¾ããããBoost TestãGoogle Testãªã©ã¨æ¯ã¹ã¦å人çã«ã¨ã¦ãå¬ããã§ãã
ã¢ã³ããã¥ã¡ã³ãã§ããããã½ã¼ã¹ã³ã¼ããèªã¿ãªãã試ãã«èªåã§ã«ã¹ã¿ã ãããã£ã¼ãæ¸ãã¦ã¿ã¾ãããoperator==ã§æ¯è¼ããisãããã£ã¼ãæ¸ãã¦ã¿ã¾ããã
ãµã³ãã«
#define CATCH_CONFIG_MAIN #include <catch.hpp> #include <catch_runner.hpp> namespace Catch { namespace Matchers { template <typename T> class Is : public Impl::MatcherImpl<Is<T>, T> { private: T const& expected; public: Is(T const& expected) : expected(expected) {} Is(Is const& other) : expected(other.expected) {} bool match(T const& actual) const override { return expected == actual; } std::string toString() const override { std::ostringstream oss; oss << "is actual. but it was expected \"" << std::boolalpha << expected << "\""; return oss.str(); } }; template <typename T> Is<T> is(T const& expected) { return Is<T>(expected); } } } #include <vector> TEST_CASE("vector", "[vector]") { using namespace Catch::Matchers; std::vector<int> sut; SECTION("è¦ç´ ã空ã®æ", "[empty]") { REQUIRE_THAT(sut.empty(), is(true)); REQUIRE_THAT(sut.size(), is(0)); } SECTION("è¦ç´ ã1件ããæ") { sut.push_back(1); REQUIRE_THAT(sut.empty(), is(false)); REQUIRE_THAT(sut.size(), is(1)); REQUIRE_THAT(sut[0], is(1)); } SECTION("è¦ç´ ã2件ããæ") { sut.push_back(1); sut.push_back(2); REQUIRE_THAT(sut.empty(), is(false)); REQUIRE_THAT(sut.size(), is(2)); REQUIRE_THAT(sut[0], is(1)); REQUIRE_THAT(sut[1], is(2)); } }
å®è¡çµæ
All tests passed (9 assertions in 1 test case) ç¶è¡ããã«ã¯ä½ããã¼ãæ¼ãã¦ãã ãã . . .