kward / shunit2

shUnit2 is a xUnit based unit test framework for Bourne based shell scripts.
Apache License 2.0
1.58k stars 212 forks source link

Documentation: JUNIT output setup defined #181

Open rapolas-oag opened 1 month ago

rapolas-oag commented 1 month ago

It seems that JUnit report support was released with the last merge, however there is no documentation how to use and setup. I would appreciate the readme.md update.

PR #176 @williamdes / @AJIOB

rapolas-oag commented 1 month ago

Found the way to get output file:

./shunit2/shunit2 -- --output-junit-xml=/output/junit.xml

Having -- -- is not intuitive, I managed to get this only by looking into tests.

AJIOB commented 1 month ago

The shellcheck itselfs waits script_name as a $1 argument or -- for skipping it. --output-junit-xml=<file> is a usual argument.

wiki5 commented 2 weeks ago

when I tried to use following in my test script, ones executed it gives an error. The inclusion of junit to generate report file:

main() { . ../../shunit2/shunit2/shunit2 --output-junit-xml=junit.xml }

Output : shunit2:FATAL unable to read from --output-junit-xml=junit.xml

I tried using below as well as mentioned in the comments here. main() { . ../../shunit2/shunit2/shunit2 -- --output-junit-xml=junit.xml }

Output: $ ./test_extract_delta.sh --output-junit-xml=junit.xml ../../shunit2/shunit2/shunit2: line 1057: eval: --: invalid option eval: usage: eval [arg ...] ASSERT:unknown failure encountered running a test

Ran 1 test.

FAILED (failures=1)

Can someone please guide me on how to generate Junit similar test reports for the unit tests I have written using shunit2?

AJIOB commented 2 weeks ago

Hi @wiki5

I'm running the latest master revision with the following code:

env \
        XUNIT_LAUNCHER="${REPO_ROOT}/external/shunit2/shunit2" \
    "./helloWorldTest.sh" \
        -- \
        "--output-junit-xml=mysuit.xml" \
        "--suite-name=myprefix::mysuit" \

The helloWorldTest.sh file contains:

#!/bin/sh

testUnitFrameworkWorks() {
    assertEquals 1 1
}

# Launch tests
. "${XUNIT_LAUNCHER}"
wiki5 commented 2 weeks ago

Thank you let me try this out.