'How to redirect JUnit testing to the console in Eclipse?

I am a blind screen reader user and have a problem with JUnit in Eclipse.

The results of tests passing or failing is represented as far as I understand visually, by highlighting the test green or red in the JUnit view. Using my screen reader I am unable to determine what the result is, so I was thinking that I could review the JUnit results if they were redirected to the console. How could this be done? Alternatively, do any other screen reader users here use Eclipse and/or JUnit and if so how do you review the results?



Solution 1:[1]

So, @Little-Santi 's answer provides the way to run JUnit tests and have the results printed in the console, but I found I didnt have to do this in order for JUnit tests to be screen reader accessible.

A suggestion was provided by @Little-Santi in the comments to try using the checkbox for showing only fails/errors. This does the trick for me as a screen reader user, because I don't really care about the tests that pass and want to examine the ones that dont. So, for any screen reader users that might stumble here, here is a brief guide for reviewing JUnit test results as a screen reader user:

Run your JUnit tests in the standard Eclipse way. Your focus should be moved to the tree view where you can go through the various Junit test results. Shift+tabbing allows you to review the number of tests passing, failing, and errors. Shift+tabbing further navigates you to a checkbox for only showing fails/errors in the tree view. tabbing forward from the tree view navigates to a list that contains the stack trace for the test selected in the tree view.

Happy testing!

Solution 2:[2]

You might execute JUnit through its command-line interface, which will produce a text output. But I must advance you that it is annoying to configure:

  1. Ensure you have the JUnit library included into the classpath: Open the project's context menu > Build Path > Add libraries... > Junit > Junit 4.

Now let's create a run execution:

  1. Open the project's context menu > Run as > Java Application > Select JUnitCore > Press OK. This will create an execution named "JUnitCore" and run it, but since it is not still configured, it will produce errors. Ignore them.
  2. Open the project's context menu > Run as > Run configurations... > JUnitCore:
    • In Arguments Tab: Under "program arguments", type in all the test classes names, separated by blank.
    • In Classpath Tab: Under "user entries", execute "Advanced" > "Add Folders" > and select the classes folders. (Depending on your project's nature, might be "build", or "target/classes" and "target/test-classes".)
    • Press "Apply".

You have ended configuring. From now on, every time you want to execute the JUnit tests of your project, just open the project's context menu, and execute Run as > Run Configurations... > JUnitCore. The output will be produced on the console tab, according to this format:

  • The first line is just a comment saying "JUnit version 4.12".
  • The second line is a summary of the tests' execution: There is a symbol for each test: A period means "OK", and an "E" means error or failure.
  • Anyway, the next lines contain a more verbose description of each error or failure, which is the part you are more interested on. Included into each error there is the full stack trace, which may make ir hard to read.

Solution 3:[3]

You should expand the tree view and put the cursor to the item that failed. Then, press applications key and hit copy failure list. You can copy the result in any text editor and enjoy! Happy testing.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adam Kurkiewicz
Solution 2 Little Santi
Solution 3 hamidreza75