Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio cannot resolve org.junit

I am using JUnit tests in Android Studio 1.2.2. The tests run without a problem. The only thing that puzzles me is that Android Studio cannot resolve the actual org.junit package. Obviously it does resolve it otherwise the tests wouldn't run. But the import and annotations are marked red in Android Studio as shown here. Is this a bug in Android Studio? I tried rebuilding the app and restarting Android Studio but this doesn't correct the problem.

import org.junit.Test;  import static org.junit.Assert.*; // cannot resolve symbol 'junit'  public class CanadaTest {     @Test     public void testCountryName() throws Exception     {         int x = 0;         x++;     } } 
like image 760
Johann Avatar asked Jul 15 '15 15:07

Johann


People also ask

Which package should you import while using JUnit?

Explanation: The default JUnit package is “org,junit”.


2 Answers

Try File -> Invalidate Caches / Restart.

like image 124
ligi Avatar answered Sep 21 '22 09:09

ligi


Put this in your gradle file:

 testCompile 'junit:junit:4.12' 
like image 21
rupesh jain Avatar answered Sep 20 '22 09:09

rupesh jain