diff options
author | alexv-smirnov <alex@ydb.tech> | 2023-03-16 13:59:59 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2023-03-16 13:59:59 +0300 |
commit | 648fc9d7949c88a6ebaaf110289b8b4536bb9a16 (patch) | |
tree | c46c89a2e46516c986af3e4ecb44d927bbdfcbac /library/cpp/testing/unittest/junit.h | |
parent | 4568fe3f6ddb72499ef17f5e0a1e7e2475a9570b (diff) | |
download | ydb-648fc9d7949c88a6ebaaf110289b8b4536bb9a16.tar.gz |
JUnitXML output for unittest
Diffstat (limited to 'library/cpp/testing/unittest/junit.h')
-rw-r--r-- | library/cpp/testing/unittest/junit.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/library/cpp/testing/unittest/junit.h b/library/cpp/testing/unittest/junit.h new file mode 100644 index 0000000000..f5113c290e --- /dev/null +++ b/library/cpp/testing/unittest/junit.h @@ -0,0 +1,82 @@ +#include "registar.h" + +namespace NUnitTest { + +class TJUnitProcessor : public ITestSuiteProcessor { + struct TTestCase { + TString Name; + bool Success; + TVector<TString> Failures; + + size_t GetFailuresCount() const { + return Failures.size(); + } + }; + + struct TTestSuite { + TMap<TString, TTestCase> Cases; + + size_t GetTestsCount() const { + return Cases.size(); + } + + size_t GetFailuresCount() const { + size_t sum = 0; + for (const auto& [name, testCase] : Cases) { + sum += testCase.GetFailuresCount(); + } + return sum; + } + }; + +public: + TJUnitProcessor(TString file, TString exec) + : FileName(file) + , ExecName(exec) + { + } + + ~TJUnitProcessor() { + Save(); + } + + void OnError(const TError* descr) override { + auto* testCase = GetTestCase(descr->test); + testCase->Failures.emplace_back(descr->msg); + } + + void OnFinish(const TFinish* descr) override { + GetTestCase(descr->test)->Success = descr->Success; + } + +private: + TTestCase* GetTestCase(const TTest* test) { + auto& suite = Suites[test->unit->name]; + return &suite.Cases[test->name]; + } + + void Save(); + + size_t GetTestsCount() const { + size_t sum = 0; + for (const auto& [name, suite] : Suites) { + sum += suite.GetTestsCount(); + } + return sum; + } + + size_t GetFailuresCount() const { + size_t sum = 0; + for (const auto& [name, suite] : Suites) { + sum += suite.GetFailuresCount(); + } + return sum; + } + +private: + TString FileName; + TString ExecName; + TMap<TString, TTestSuite> Suites; +}; + +} // namespace NUnitTest |