Android Studio Cannot resolve the "To" character in org.junit import.

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;" to my java class. I get the error “cannot resolve the“ Before ”character (this also happens with“ Test ”), although I see that the files exist in my junit package (see image). I also have a dependency specified in my gradle (see 2nd image).

I noticed that someone else asked a similar question, and the answer was "Make sure that if JUnit is declared as <scope> test </scope>, your test class is in src / test, otherwise it will not be able to see addiction. "

This may be my problem, but I'm not sure how to make sure my "test class is in src / test". (I'm new to android studio ... sorry if this is a simple question)

Classes Before and Test

Gradle Dependencies

+4
source share
6 answers

I was able to solve this problem by following these steps:

Step 1: Move from the Android view to the Projects view

Step 2: now in the application folder you should see libs, if you do not see it, create it

Step 3. Drag and drop the .jar file here, you can get the invitation "This file does not belong to the project", just click "OK"

4: jar libs, jar " ", "" " "

5: ! .

0

Android Studio 2.0 Beta 7

1) > .

2) build.gradle add

dependencies{
    androidTestCompile 'junit:junit:4.12'
}

3) :

1) > .

2) .

3) . junit: junit: 4.12.

.

4) "".

.

+3

Android- /src/main. unit test /src/test, :

This screenshot in the Android Studio project view shows the difference.

, . , , Test Artifact "Unit Tests".

Show here

, , .

+1

, Debug. , "Release".

+1

​​ , Android Studio 2.2.6 reimport. 2.2.6. .

0

testCompile build.gradle.

Changing this setting to androidTestCompilefixed the problem for me.

androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.mockito:mockito-core:1.10.19'
0
source

All Articles