In this tutorial, we will create some tests in Ruby using Minitest and the "minitest-reporters" gem.
The "minitest-junit" could also be used, with minor changes to the code below, particularly in the "test_helper.rb".
- Install minitest and minitest-reporters gem (or the "minitest-junit" gem as an alternative)
The code that follows is from the minitest github project.
Let's start by using a sample Ruby class.
The tests will require some common code that can be written in a "test_helper" Ruby script.
Writing some unit tests is straightforward.
MiniTest also supports RSpec-like features such as the ability to use "specs". In this case, the test is wrapped inside one or multiple "describe" blocks, and is consubstantiated in an "it" block.
The two different approaches are valid and their results should be similar.
After running the tests and generating the JUnit XML report(s), it/they can be imported to Xray (either by the REST API or through the Import Execution Results action within the Test Execution).
Several JUnit XML will be produced:
TEST-MemeTest.xml contains the results of the unit tests. The other two files contain results related to the "spec" test.
Note: This example could be further optimized to obtain just a JUnit XML file containing the results for the two different test classes.
The test is mapped to a Generic Test in Jira, and the Generic Test Definition field contains the name of Ruby test class concatenated with the name of the method that implements the test case.
The Execution Details of the Generic Test contains information about the Test Suite, which in the case of the unit tests, corresponds to the name of the class.
For the spec-related tests, they're mapped in a slightly different way: the multiple "describe" are concatenated using "::", along with the name of the "it" block, preceded by "test_<counter>".