lundi 27 juillet 2020

JUnit get Result instance after Test

I am working on a Testframework, which uses JUnit 4.12.

Now I have a bit of a special Request: After the execution of a complex test script, the User wants to get the number of Failures that occurred during the execution (persist them somewhere else). Result#getFailureCount() seems perfect for this Task (https://junit.org/junit4/javadoc/4.12/org/junit/runner/Result.html).

My Problem is how to obtain the Result instance of the executed script. I found following Link https://www.logicbig.com/tutorials/unit-testing/junit/junit-core.html. The Result instance is obtained with the code below run in a main method:

JUnitCore jUnitCore = new JUnitCore();
Result result = jUnitCore.run(TestExample.class);

Since all our scripts are annotated with @Test and are triggered by a buildserver, this is not an option to me. Is there a way to obtain the Instance of Result in the same class which was ran as test?

Aucun commentaire:

Enregistrer un commentaire