| 389 | } |
| 390 | |
| 391 | void TJUnitProcessor::SerializeToJson() { |
| 392 | TFileOutput out(ResultReportFileName); |
| 393 | NJsonWriter::TBuf json(NJsonWriter::HEM_UNSAFE, &out); |
| 394 | json.SetIndentSpaces(1); |
| 395 | json.BeginObject(); |
| 396 | { |
| 397 | json.WriteKey("tests"sv).WriteInt(GetTestsCount()); |
| 398 | json.WriteKey("failures"sv).WriteInt(GetFailuresCount()); |
| 399 | json.WriteKey("testsuites"sv).BeginList(); |
| 400 | for (const auto& [suiteName, suite] : Suites) { |
| 401 | json.BeginObject(); |
| 402 | json.WriteKey("name"sv).WriteString(suiteName); |
| 403 | json.WriteKey("id"sv).WriteString(suiteName); |
| 404 | json.WriteKey("tests"sv).WriteInt(suite.GetTestsCount()); |
| 405 | json.WriteKey("failures"sv).WriteInt(suite.GetFailuresCount()); |
| 406 | json.WriteKey("time"sv).WriteDouble(suite.GetDurationSeconds()); |
| 407 | json.WriteKey("testcases"sv).BeginList(); |
| 408 | for (const auto& [testName, test] : suite.Cases) { |
| 409 | json.BeginObject(); |
| 410 | json.WriteKey("classname"sv).WriteString(suiteName); |
| 411 | json.WriteKey("name"sv).WriteString(testName); |
| 412 | json.WriteKey("id"sv).WriteString(testName); |
| 413 | json.WriteKey("time"sv).WriteDouble(test.DurationSecods); |
| 414 | json.WriteKey("failures"sv).BeginList(); |
| 415 | for (const auto& failure : test.Failures) { |
| 416 | json.BeginObject(); |
| 417 | json.WriteKey("message"sv).WriteString(failure.Message); |
| 418 | json.WriteKey("type"sv).WriteString("ERROR"sv); |
| 419 | if (failure.BackTrace) { |
| 420 | json.WriteKey("backtrace"sv).WriteString(failure.BackTrace); |
| 421 | } |
| 422 | json.EndObject(); |
| 423 | } |
| 424 | json.EndList(); |
| 425 | |
| 426 | if (!test.StdOut.empty()) { |
| 427 | json.WriteKey("system-out"sv).WriteString(test.StdOut); |
| 428 | } |
| 429 | if (!test.StdErr.empty()) { |
| 430 | json.WriteKey("system-err"sv).WriteString(test.StdErr); |
| 431 | } |
| 432 | json.EndObject(); |
| 433 | } |
| 434 | json.EndList(); |
| 435 | json.EndObject(); |
| 436 | } |
| 437 | json.EndList(); |
| 438 | } |
| 439 | json.EndObject(); |
| 440 | } |
| 441 | |
| 442 | class TXmlWriter { |
| 443 | public: |
nothing calls this directly
no test coverage detected