Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should JUnit tests be javadocced?

I have a number of JUnit test cases that are currently not documented with Javadoc comments.

The rest of my code is documented, but I'm wondering if it's even worth the effort to document these tests.

like image 506
Jim Avatar asked Nov 26 '09 16:11

Jim


People also ask

Should JUnit test throw exception?

The JUnit TestRunners will catch the thrown Exception regardless so you don't have to worry about your entire test suite bailing out if an Exception is thrown. This is the best answer. I'll add that I think the question here is one of style: catch-and-fail, or throw? Normally, best practice avoids "throws Exception".

Are JUnit tests run in parallel?

Once the parallel execution property is set (or enabled), the JUnit Jupiter engine will run the tests in parallel as per the configurations provided with the synchronization mechanisms.

Does JUnit support black box testing?

However, despite "unit" being part of its name, JUnit by itself is not limiting you to Unit testing, so it does not impose either a white-box nor a black-box approach. You can use JUnit to do any kind of testing that you like.


2 Answers

If the purpose of the test is obvious, I don't bother documenting it.

If it's non-obvious because it deals with some obscure situation - or if I want to refer to a specific bug, for example - in that case I'll add documentation. I don't document exceptions throw etc though - just a quick summary of the method. This happens relatively rarely. I'm more likely to add documentation for helper methods used within multiple tests.

like image 120
Jon Skeet Avatar answered Oct 10 '22 03:10

Jon Skeet


I don't find any value in javadocing the test cases. I just make the method name descriptive enough to know the purpose of the test.

In Ruby, I know there are tools to create a document from the name of the tests, but I haven't seen one of these in Java.

like image 41
Kaleb Brasee Avatar answered Oct 10 '22 03:10

Kaleb Brasee