I am using the junit-4.12 external library package in my Android Studio project. For some reason, when I import "import org.junit.Before;" into my java class I get the error "cannot resolve symbol 'Before'" (this is also happening with 'Test'), even though I can see that the files exists in my junit package (see image). I also have the dependency listed in my gradle (see 2nd image).
I noticed that someone else asked a similar question and the response was "Make sure that if JUnit is declared as < scope>test< / scope >, that your test class is in src/test, otherwise it won't be able to see the dependency."
Maybe this is my problem, but I am not sure how to make sure that my "test class is in src/test". (I am new to android studio... so sorry if this is a simple question)
"Before" and "Test" classes
Gradle Dependencies
Using Android Studio 2.0 Beta 7
1)Go To Build > Clean Project.
2)In apps build.gradle add
dependencies{
androidTestCompile 'junit:junit:4.12'
}
3)Steps :
1)Go To File > Project Structure.
2)Select your app from modules.
3)Go To Dependencies. Select junit:junit:4.12.
Select Test Compile.
4)Click Ok.
Import errors should get resolved.
Be shure you are on Debug build variant. It doesn't work, if "Release" variant is chosen.
In an Android project, the normal app code lives under app/src/main. The unit test code then lives under app/src/test, as you can see here:
Notice that the test code area is highlighted in green. Also, to work with unit tests, you should also set your build variants Test Artifact to "Unit Tests".
The screen here shows it on instrumentation tests, which is the default, so you you'll need to select unit tests from the dropdown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With