Referencing attachments in the JUnit XML
If you can't name the files after their test cases, reference them in the JUnit XML instead:
- Workflow Editor
- Configuration YAML
-
Generate a
JUnit.xmlfile from your tests.The general file structure should look something like this:
<?xml version="1.0" encoding="UTF-8"?><testsuites time="15.682687"><testsuite name="Tests.Registration" time="6.605871"><testcase name="testCase1" classname="Tests.Registration" time="2.113871" /></testsuite></testsuites> -
Add a
<properties>element to associate an attachment with atestcase.The
nameattribute of the element must be set with a valueattachment_#where#is the ordered index of the attachment file, and the value is the filename. Bitrise will show attachments for any test with the attachment properties, but it's most common to only attach screenshots to failed tests. Mark a test as failed with a<failure>element.<testcase name="testCase1" classname="Tests.Registration" time="2.113871" /><failure message="Assertion error message" type="AssertionError">Call stack printed here</failure><properties><property name="attachment_1" value="pp1.jpg" /><property name="attachment_2" value="pp2.jpg" /></properties></testcase> -
Add the Export test results to Test Reports Step to your Bitrise Workflow. It should be version 1.1.0 or higher.
-
Set a test name in the The name of the test input.
-
Set the path to your JUnit XML file in the Test result search pattern input.
-
Add the Deploy to Bitrise.io Step to the end of your Workflow.
You don't have to change the default input values.
-
Generate a
JUnit.xmlfile from your tests.The general file structure should look something like this:
<?xml version="1.0" encoding="UTF-8"?><testsuites time="15.682687"><testsuite name="Tests.Registration" time="6.605871"><testcase name="testCase1" classname="Tests.Registration" time="2.113871" /></testsuite></testsuites> -
Add a
<properties>element to associate an attachment with atestcase.The
nameattribute of the element must be set with a valueattachment_#where#is the ordered index of the attachment file, and the value is the filename. Bitrise will show attachments for any test with the attachment properties, but it's most common to only attach screenshots to failed tests. Mark a test as failed with a<failure>element.<testcase name="testCase1" classname="Tests.Registration" time="2.113871" /><failure message="Assertion error message" type="AssertionError">Call stack printed here</failure><properties><property name="attachment_1" value="pp1.jpg" /><property name="attachment_2" value="pp2.jpg" /></properties></testcase> -
Add the
custom-test-results-exportStep to your Bitrise Workflow after generating your JUnit XML file. It should be version 1.1.0 or higher.workflows:inline_attachment:steps:- generate-text-file:inputs:- file_name: junit.xml- file_content: "xml content with references to image files here"- custom-test-results-export: -
Set a test name in the
test_nameinput.- custom-test-results-export@1:inputs:- test_name: example_tests -
Set the path to your JUnit XML file in the
search_patterninput.- custom-test-results-export@1:inputs:- test_name: example_tests- search_pattern: junit.xml -
Add the
deploy-to-bitrise-ioStep to the end of your Workflow.You don't have to change the default input values. The full Workflow in your configuration YAML file might look something like this:
workflows:inline_attachment:steps:- generate-text-file@0:inputs:- file_name: junit.xml- file_content: "xml content with references to image files here"- custom-test-results-export@1:inputs:- test_name: example_tests- base_path: "."- search_pattern: junit.xml- script@1:inputs:- content: |#!/usr/bin/env bashset -exset -o pipefailTEST_RESULTS_DIR=$(find "$BITRISE_TEST_DEPLOY_DIR" -type d -name "example_tests" -print -quit)cp ~/*.jpg $TEST_RESULTS_DIRtitle: Copy image files to test directory- deploy-to-bitrise-io@2: {}