Essential Android Unit testing in Android with JUnit edit forum

Static import

JUnit defines quite some assertEquals methods at least one for each primitive type and one for Objects is available. These methods are by default not directly available to call and should be called like this: Assert.assertEquals. But because these methods are used so often people almost always use a static import so that the method can be directly used as if it is part of the class itself.

To add a static import for the assertEquals method use the following import statement:

import static org.junit.Assert.assertEquals;

You can also static import all assert methods including the assertArrayEquals, assertNotNull and assertFalse etc. using the following static import:

import static org.junit.Assert.*;

Without static import:

public void addition_isCorrect(){
    Assert.assertEquals(4 , 2 + 2);

With static import:

public void addition_isCorrect(){
    assertEquals(4 , 2 + 2);

Table Of Contents
64 Menu
80 Unit testing in Android with JUnit
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close