150

I bump version of junit to 4.11 and get:

[WARNING] [deprecation] Assert in junit.framework has been deprecated
[WARNING] [deprecation] Assert in junit.framework has been deprecated
....

How and to what migrate?

7 Answers 7

264

As it seems the Assert class has been moved from junit.framework to org.junit.Assert in JUnit 4.0 - you can use that instead, it's not deprecated.

3
  • 10
    How would I go about telling eclipse never to use the deprecated junit.framework ever again?
    – atripes
    Commented Dec 29, 2014 at 10:58
  • 7
    To atrioom: Window » Preferences » Java » Appearence » Type Filters, then add junit.framework.Assert.* Commented Jan 12, 2016 at 21:53
  • 9
    @atrioom: I think you can also add java.awt.List while your at it :P Commented Apr 22, 2016 at 10:44
86

Change your import statement from

import junit.framework.Assert;

to

import org.junit.Assert; 

and this will rectify your JUnit deprecation warnings.

0
19

Both are depricated:

junit.framework.Assert.assertThat
org.junit.Assert.assertThat

According to docs, use Instead:

org.hamcrest.MatcherAssert.assertThat
1
5

After facing this problem I have tried lots of ways to solve this but failed again and again.

The good thing is: I have download junit-4.12.jar file from here and added the jar file in the project section under the libs folder. If previously any kind of Junit dependancy exist in the project then remove that from the build.gradle and build + clean your project.

It is worked for me. Hope it will work for you.

Note: Take a look in the image that I attached in below.

Thank you

enter image description here

1
  • This solution worked for me, i just removed the dependency fandroidTestImplementation 'junit:junit:4.12' from the build.gradle(App level) and place the junit-4.12.jar in the app\libs directory and build the project, thanks man, you saved me
    – Ali Tamoor
    Commented Aug 29, 2019 at 10:03
2

We had a large number of tests with many assertions.

Adding something like

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

to the import statements also helped to limit the changes in test code.

1

According to JUnit5 Doc. assertions in JUnit 5 are moved to org.junit.jupiter.api.Assertions.

For example,

JUnit 4 import org.junit.Assert

becomes

import org.junit.jupiter.api.Assertions in JUnit 5.

0

You can refer to jUnit4 Assert class methods from JUnit4

Not the answer you're looking for? Browse other questions tagged or ask your own question.