1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00
denoland-deno/tests/testdata/test/nested_failures.junit.out
Yusuke Tanaka 64e8c36805
fix(cli): output more detailed information for steps when using JUnit reporter (#22797)
This patch gets JUnit reporter to output more detailed information for
test steps (subtests).

## Issue with previous implementation

In the previous implementation, the test hierarchy was represented using
several XML tags like the following:

- `<testsuites>` corresponds to the entire test (one execution of `deno
test` has exactly one `<testsuites>` tag)
- `<testsuite>` corresponds to one file, such as `main_test.ts`
- `<testcase>` corresponds to one `Deno.test(...)`
- `<property>` corresponds to one `t.step(...)`

This structure describes the test layers but one problem is that
`<property>` tag is used for any use cases so some tools that can ingest
a JUnit XML file might not be able to interpret `<property>` as
subtests.

## How other tools address it

Some of the testing frameworks in the ecosystem address this issue by
fitting subtests into the `<testcase>` layer. For instance, take a look
at the following Go test file:

```go
package main_test

import "testing"

func TestMain(t *testing.T) {
  t.Run("child 1", func(t *testing.T) {
    // OK
  })

  t.Run("child 2", func(t *testing.T) {
    // Error
    t.Fatal("error")
  })
}
```

Running [gotestsum], we can get the output like this:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="3" failures="2" errors="0" time="1.013694">
	<testsuite tests="3" failures="2" time="0.510000" name="example/gosumtest" timestamp="2024-03-11T12:26:39+09:00">
		<properties>
			<property name="go.version" value="go1.22.1 darwin/arm64"></property>
		</properties>
		<testcase classname="example/gosumtest" name="TestMain/child_2" time="0.000000">
			<failure message="Failed" type="">=== RUN   TestMain/child_2&#xA;    main_test.go:12: error&#xA;--- FAIL: TestMain/child_2 (0.00s)&#xA;</failure>
		</testcase>
		<testcase classname="example/gosumtest" name="TestMain" time="0.000000">
			<failure message="Failed" type="">=== RUN   TestMain&#xA;--- FAIL: TestMain (0.00s)&#xA;</failure>
		</testcase>
		<testcase classname="example/gosumtest" name="TestMain/child_1" time="0.000000"></testcase>
	</testsuite>
</testsuites>
``` 

This output shows that nested test cases are squashed into the
`<testcase>` layer by treating them as the same layer as their parent,
`TestMain`. We can still distinguish nested ones by their `name`
attributes that look like `TestMain/<subtest_name>`.

As described in #22795, [vitest] solves the issue in the same way as
[gotestsum].

One downside of this would be that one test failure that happens in a
nested test case will end up being counted multiple times, because not
only the subtest but also its wrapping container(s) are considered to be
failures. In fact, in the [gotestsum] output above, `TestMain/child_2`
failed (which is totally expected) while its parent, `TestMain`, was
also counted as failure. As
https://github.com/denoland/deno/pull/20273#discussion_r1307558757
pointed out, there is a test runner that offers flexibility to prevent
this, but I personally don't think the "duplicate failure count" issue
is a big deal.

## How to fix the issue in this patch

This patch fixes the issue with the same approach as [gotestsum] and
[vitest].
More specifically, nested test cases are put into the `<testcase>` level
and their names are now represented as squashed test names concatenated
by `>` (e.g. `parent 2 > child 1 > grandchild 1`). This change also
allows us to put a detailed error message as `<failure>` tag within the
`<testcase>` tag, which should be handled nicely by third-party tools
supporting JUnit XML.

## Extra fix

Also, file paths embedded into XML outputs are changed from absolute
path to relative path, which is helpful when running the test suites in
several different environments like CI.

Resolves #22795

[gotestsum]: https://github.com/gotestyourself/gotestsum
[vitest]: https://vitest.dev/

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2024-03-26 00:08:46 +09:00

47 lines
2.7 KiB
XML

Check file:///[WILDCARD]/test/nested_failures.ts
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="deno test" tests="11" failures="6" errors="0" time="[WILDCARD]">
<testsuite name="./test/nested_failures.ts" tests="11" disabled="0" errors="0" failures="6">
<testcase name="parent 1" classname="./test/nested_failures.ts" time="[WILDCARD]" line="1" col="6">
<failure message="1 test step failed">1 test step failed.</failure>
</testcase>
<testcase name="parent 2" classname="./test/nested_failures.ts" time="[WILDCARD]" line="8" col="6">
<failure message="2 test steps failed">2 test steps failed.</failure>
</testcase>
<testcase name="parent 3" classname="./test/nested_failures.ts" time="[WILDCARD]" line="20" col="6">
</testcase>
<testcase name="parent 1 &gt; child 1" classname="./test/nested_failures.ts" time="[WILDCARD]" line="2" col="11">
</testcase>
<testcase name="parent 1 &gt; child 2" classname="./test/nested_failures.ts" time="[WILDCARD]" line="3" col="11">
<failure message="Uncaught Error: Fail.">Error: Fail.
throw new Error(&quot;Fail.&quot;);
^
at file:///[WILDCARD]/test/nested_failures.ts:4:11
[WILDCARD]</failure>
</testcase>
<testcase name="parent 2 &gt; child 1" classname="./test/nested_failures.ts" time="[WILDCARD]" line="9" col="11">
<failure message="1 test step failed">1 test step failed.</failure>
</testcase>
<testcase name="parent 2 &gt; child 1 &gt; grandchild 1" classname="[WILDCARD]/test/nested_failures.ts" time="[WILDCARD]" line="10" col="13">
</testcase>
<testcase name="parent 2 &gt; child 1 &gt; grandchild 2" classname="[WILDCARD]/test/nested_failures.ts" time="[WILDCARD]" line="11" col="13">
<failure message="Uncaught Error: Fail.">Error: Fail.
throw new Error(&quot;Fail.&quot;);
^
at file:///[WILDCARD]/test/nested_failures.ts:12:13
[WILDCARD]</failure>
</testcase>
<testcase name="parent 2 &gt; child 2" classname="./test/nested_failures.ts" time="[WILDCARD]" line="15" col="11">
<failure message="Uncaught Error: Fail.">Error: Fail.
throw new Error(&quot;Fail.&quot;);
^
at file:///[WILDCARD]/test/nested_failures.ts:16:11
[WILDCARD]</failure>
</testcase>
<testcase name="parent 3 &gt; child 1" classname="./test/nested_failures.ts" time="[WILDCARD]" line="21" col="11">
</testcase>
<testcase name="parent 3 &gt; child 2" classname="./test/nested_failures.ts" time="[WILDCARD]" line="22" col="11">
</testcase>
</testsuite>
</testsuites>
error: Test failed