androidunit-testingintellij-idearobolectricrobolectric-gradle-plugin

cannot create "test" folder in android studio for robolectric


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


Solution

  • 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'] }
      }
    }