Does JUnit Parser require the classname and name attributes to be non-empty?
Asked by Hans Sebastian:

I have a bamboo plan and have Junit Parser as one of the tasks for its run. This is bamboo 3.3.2 build 2718.

I have two test results files in the same dir that I want JUnit Parser to pick up. The results are like this:

* test/foo.xml
* test/bar.xml

In the JUnit Parser, I put test/\*.xml for the custom results directories. When I run, I only get results from bar.xml and the total number of tests is just coming rom bar.xml.

The difference other than the content of the tests is that classname and name attributes are blank in foo.xml:

foo.xml

```
&lt;testsuite name="" errors="7" failures="8" skips="0" tests="17" time="1.531"&gt;  &lt;testcase classname="" name="tests.test_app" time="0"&gt;    &lt;failure message="collection failure"&gt;/home/foo/_path/local.py:529: in pyimportE   ImportError: No module named Rest&lt;/failure&gt;&lt;/testcase&gt;  &lt;testcase classname="" name="api.__init__" time="0"/&gt;
```

bar.xml

```
&lt;testsuite tests="583" errors="0" failures="0" skipped="0" name="contrib.AnonymousUserBackendTest" time="0.234"&gt;  &lt;testcase classname="contrib.AnonymousUserBackendTest" name="test_get_all_permissions" time="0.002"/&gt;  &lt;testcase classname="contrib.AnonymousUserBackendTest" name="test_has_module_perms" time="0.000"/&gt;
```

So, does JUnit Parser require the classname and name attributes to be non-empty? Is there any other reason the results are not picked up?

Thanks


Answers:
author: James Dumay
body: G'day,

Yes you need to provide a name for the testsuite and test class in the test results for the file to be considered a valid JUnit report by Bamboo.

What testing framework is generating that output?

Thanks

James

comments: author: Hans Sebastian
body: We use py.test

```
(env26_qa)[hsebastian@puri removeme]$  python --versionPython 2.6.1(env26_qa)[hsebastian@puri removeme]$  py.test --versionThis is py.test version 2.1.3, imported from /Users/hsebastian/zion_repo/env26_qa/lib/python2.6/site-packages/pytest.pyc(env26_qa)[hsebastian@puri removeme]$  cat test_filename.py import invalidmoduleclass TestClassName(object):    def test_method_name(self):        pass(env26_qa)[hsebastian@puri removeme]$  py.test --junitxml results.xmlplatform darwin -- Python 2.6.1 -- pytest-2.1.3collected 0 items / 1 errors ____________________________________________________________________________________________________ ERROR collecting test_filename.py _____________________________________________________________________________________________________test_filename.py:1: in <module>>   import invalidmoduleE   ImportError: No module named invalidmodule----------------------------------------------------------------------------------------------------- generated xml file: results.xml ------------------------------------------------------------------------------------------------------(env26_qa)[hsebastian@puri removeme]$  cat results.xml <?xml version="1.0" encoding="utf-8"?><testsuite name="" errors="1" failures="0" skips="0" tests="0" time="0.009" ><testcase classname="" name="test_filename" time="0"><failure message="collection failure">test_filename.py:1: in &lt;module&gt;&gt;   import invalidmoduleE   ImportError: No module named invalidmodule</failure></testcase></testsuite>(env26_qa)[hsebastian@puri removeme]$  

```

Thanks for confirming my observation. I'll look into py.test to see if there is a way for the values to be inserted even though the setup failed. I am pretty sure older version of py.test did not behave like this.


author: James Dumay
body: Think you could email me the reports that failed to parse? I think we should add some sensible behavior for when we get reports with data missing. My email is [james@atlassian.com](mailto:james@atlassian.com)


author: Hans Sebastian
body: I think the results.xml i pasted above should be sufficient to repro this. I haven't tried it though but the nature is similar. Otherwise, I can send you the reports from an actual bamboo run, but I need your email address. :) I could not find it on this website.


author: Ed C
body: Hi, have you found a way to get py.test to fill these testsuite name value? I have run into the same issue


author: sseveringhaus-newclassrooms
body: I hit this same issue. Bamboo would successfully pass or fail the build based on the test results, but it wouldn't display any of them, instead just giving the cryptic "No failed tests found, a possible compilation error occurred" message.

In my particular case, I'm using dotnet test, which generates Microsoft's TRX format, which I then transform to JUnit format. The transformation was not correctly picking up the className from TestDefinitions/UnitTest/TestMethod in the TRX file.

An error or warning message from the JUnit Parser plugin when testcase/@classname is missing would be very helpful.


author: Ed C
body: Hi, have you found a way to get py.test to fill these testsuite name value? I have run into the same issue


author: Ed C
body: Hi, have you found a way to get py.test to fill these testsuite name value? I have run into the same issue


author: Hans Sebastian
body: I also tried running the plan such that only foo.xml is created. Still bamboo sees no results.