Skip to content

Conversation

@Minipada
Copy link
Contributor

@Minipada Minipada commented Jan 16, 2019

What I did

I added a callback to get JUNIT files as an output.

Why I did it

In CI context, Jenkins uses JUNIT files to record tests. I have based my work on the JSON factory example.

Test output call example

test.add_output_callbacks(junit.OutputToJUNIT(
    os.path.join(path,
                  '%s_%s_%s.xml' %
                  (test_name, dut, datetime.now().strftime('%Y-%m-%d-%H-%M'))),
    indent=2))

XML example

<?xml version="1.0" ?>
<testsuites disabled="0" errors="0" failures="0" tests="6" time="14.463">
  <testsuite disabled="0" errors="0" failures="0" name="test" skipped="0" tests="6" time="14.463">
    <testcase classname="single_node_chain.io" name="trigger_phase" time="0.002000"/>
    <testcase classname="single_node_chain.io" name="test_digital_input" time="3.017000">
      <system-out>name: input_4
validators: ['x == 0']
measured_value: 0
outcome: PASS
log: Testing IO1


name: input_2
validators: ['x == 0']
measured_value: 0
outcome: PASS
log: Testing IO2

name: input_3
validators: ['x == 1']
measured_value: 1
outcome: PASS
log: Testing IO3

name: input_1
validators: ['x == 1']
measured_value: 1
outcome: PASS
log: Testing IO4

</system-out>
    </testcase>
    <testcase classname="single_node_chain.io" name="test_analog_single_ended_input" time="2.864000">
      <system-out>name: voltage_2
validators: ['1.44 &lt;= x &lt;= 1.7600000000000002']
measured_value: 1.6173095703125
outcome: PASS
log: Testing IO1
voltage 2

name: voltage_0
validators: ['-0.05 &lt;= x &lt;= 0.05']
measured_value: 0.0018310546875
outcome: PASS
log: Testing IO1
voltage 0

name: voltage_3
validators: ['2.25 &lt;= x &lt;= 2.75']
measured_value: 2.527099609375
outcome: PASS
log: Testing IO1
voltage 3

name: voltage_5
validators: ['3.6899999999999995 &lt;= x &lt;= 4.51']
measured_value: 4.1453857421875
outcome: PASS
log: Testing IO1
voltage 5


name: voltage_1
validators: ['0.72 &lt;= x &lt;= 0.8800000000000001']
measured_value: 0.80908203125
outcome: PASS
log: Testing IO1
voltage 1


name: voltage_4
validators: ['2.9699999999999998 &lt;= x &lt;= 3.63']
measured_value: 3.33642578125
outcome: PASS
log: Testing IO1
voltage 4

</system-out>
    </testcase>
  </testsuite>
</testsuites>

Test with Jenkins plugin Test results analyzer

Success

screenshot_20190116_170407

Failure

screenshot_20190116_173453

Note

I was not quite sure of what to put instead of test in line 66

return TestSuite.to_xml_string([TestSuite("test", self.test_cases)])

This change is Reviewable

@tcm0116
Copy link
Contributor

tcm0116 commented Feb 29, 2020

I need this exact feature, so I second this pull request.

@Minipada
Copy link
Contributor Author

You can take the file and add it to your project, that's what I did since it was never reviewed.

"validators: " + str(phase_data["validators"]),
"measured_value: " + str(phase_data["measured_value"]),
"outcome: " + phase_data["outcome"],
"log: " + "\n".join(log_output), "\n"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having an issue with this throwing an exception because there was no "validators" entry in the phase_data dictionary for a measurement generated by a monitor. The change below resolved that issue with me.

        if "name" in phase_data:
          output.extend(["name: " + phase_data["name"]])
        if "validators" in phase_data:
          output.extend(["validators: " + str(phase_data["validators"])])
        if "measured_value" in phase_data:
          output.extend(["measured_value: " + str(phase_data["measured_value"])])
        if "outcome" in phase_data:
          output.extend(["outcome: " + phase_data["outcome"]])
        output.extend(["log: " + "\n".join(log_output), "\n"])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants