1

I want to add robolectric tests to my project in intellij.

I have tried to follow this tutorial

but I cannot add "test" package under my main module.

In addition the "build variants" look different than in the tutorial.

how can I fix this?

how can I add test class properly?

enter image description here

Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • Which version of Android Studio and android gradle plugin do you use? Easy unit tests only supported if both is 1.1 or above. If you have already latest versions then switch to project view (your screenshots show android view) and create /src/test/java folder and then the java folder should get a green color. Should be no need to change source paths. – nenick Apr 12 '16 at 06:57

3 Answers3

7

this is not the way, the good architecture is:

/app
    /src
        /main
             /java
                  /com.your.package
        /test
             /java
                  /com.your.package

and don't forget to write it in the app module build.gradle

android {
  sourceSets {
    main { java.srcDirs = ['src/main/java'] }
    test { java.srcDirs = ['src/test/java'] }
  }
}
abdoulayeYATERA
  • 209
  • 1
  • 2
1

You need to change Project layout from Android to Project: Current layout

Select another layout

New layout

And now you can easily create folders from Android Studio UI

Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
0

I guess you had an outdated tutorial. Android Studio changed, there is no need to use Build Variants to distinguish between UnitTest and AndroidTests anymore.

Just create the TestFolders manually. e.g. app/scr/androidTest and put your test Files there.

Maybe just create a new Project with android Studio. The Folders for tests will be atomatically created, you'll see what i mean.

Rüdiger
  • 1,674
  • 1
  • 20
  • 28