Coding Guidline: Assert static import or not [message #1018628] |
Thu, 14 March 2013 04:22  |
Eclipse User |
|
|
|
When writing JUnit tests there are two possibilities for importing the Assert class:
Solution 1: static import.
It is possible to use:
import static org.junit.Assert.*
I think Eclipse convert this to
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
This allows calling assertXxxxx() functions directly in the code. For example:
assertTrue(emptyList.isEmpty());
Solution 2: normal imports.
Assert is imported with a normal import:
In the code assertXxxxx() are used with Assert class:
Assert.assertTrue(emptyList.isEmpty());
For the moment, we are using solution 2 (we had a mix of both solutions, and when I pushed code for Bug 402301, Bug 402336, Bug 402314... I migrated everything to use solution 2). It is possible to change it back to solution 1 (it is a search and replace operation + organize imports).
I do not care if we use solution 1 or 2.
I think we should agree on something. Define it as guideline. Add a Checkstyle check to ensure that every test is written the same way.
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04747 seconds