"Assert in junit.framework has been deprecated" - what next to use?

JunitJunit4

Junit Problem Overview


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?

Junit Solutions


Solution 1 - Junit

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.

Solution 2 - Junit

Change your import statement from

import junit.framework.Assert;

to

import org.junit.Assert; 

and this will rectify your JUnit deprecation warnings.

Solution 3 - Junit

Both are depricated:

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

According to docs, use Instead:

org.hamcrest.MatcherAssert.assertThat

Solution 4 - Junit

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

Solution 5 - Junit

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.

Solution 6 - Junit

You can refer to jUnit4 Assert class methods from JUnit4

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongavenkoaView Question on Stackoverflow
Solution 1 - JunitAlex StockingerView Answer on Stackoverflow
Solution 2 - JunitdmeehanView Answer on Stackoverflow
Solution 3 - JunitSalam El-BannaView Answer on Stackoverflow
Solution 4 - JunitShahadat HossainView Answer on Stackoverflow
Solution 5 - JunitsolleksView Answer on Stackoverflow
Solution 6 - JunitSandeepView Answer on Stackoverflow