|
280 | 280 | end
|
281 | 281 | end
|
282 | 282 |
|
| 283 | +@testset "Manual JUnitTestSuite/JUnitTestCase with error no logs" begin |
| 284 | + using ReTestItems: JUnitTestCase, JUnitTestSuite |
| 285 | + using Dates: datetime2unix, DateTime |
| 286 | + |
| 287 | + function get_test_suite(suite_name, test_name) |
| 288 | + ts = @testset "$test_name" begin |
| 289 | + # would rather make this false, but failing @test makes the ReTestItems test fail as well |
| 290 | + @test true |
| 291 | + end |
| 292 | + # Make the test time deterministic to make testing report output easier |
| 293 | + ts.time_start = datetime2unix(DateTime(2023, 01, 15, 16, 42)) |
| 294 | + ts.time_end = datetime2unix(DateTime(2023, 01, 15, 16, 42, 30)) |
| 295 | + |
| 296 | + # should be able to construct a TestCase from a TestSet |
| 297 | + tc = JUnitTestCase(ts) |
| 298 | + @test tc isa JUnitTestCase |
| 299 | + |
| 300 | + # once wrapped in a TestSuite, this should have enough info to write out a report |
| 301 | + suite = JUnitTestSuite(suite_name) |
| 302 | + junit_record!(suite, tc) |
| 303 | + @test suite isa JUnitTestSuite |
| 304 | + return suite |
| 305 | + end |
| 306 | + suite = get_test_suite("manual", "test") |
| 307 | + # pretend there is a failure |
| 308 | + suite.counts.failures = 1 |
| 309 | + suite.testcases[1].counts.failures = 1 |
| 310 | + |
| 311 | + mktemp() do path, io |
| 312 | + write_junit_file(path, suite) |
| 313 | + report_string = read(io, String) |
| 314 | + expected = """ |
| 315 | + <?xml version="1.0" encoding="UTF-8"?> |
| 316 | + <testsuite name="manual" timestamp="2023-01-15T16:42:00.0" time="30.0" tests="1" skipped="0" failures="1" errors="0"> |
| 317 | + \t<testcase name="test" timestamp="2023-01-15T16:42:00.0" time="30.0" tests="1" skipped="0" failures="1" errors="0"> |
| 318 | + \t\t<properties> |
| 319 | + \t\t<property name=\"dd_tags[test.id]\" value=\"$(repr(hash("test")))\"></property> |
| 320 | + \t\t</properties> |
| 321 | + \t\t<error message="Test errored but no error message was captured."> |
| 322 | + \t\t</error> |
| 323 | + \t</testcase> |
| 324 | + </testsuite> |
| 325 | + """ |
| 326 | + # leading/trailing whitespace isn't important |
| 327 | + @test strip(report_string) == strip(expected) |
| 328 | + end |
| 329 | +end |
| 330 | + |
283 | 331 | end # junit_xml.jl testset
|
0 commit comments