Elad Benda
Elad Benda

Reputation: 36654

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

Upvotes: 1

Views: 4099

Answers (3)

Eugen Martynov
Eugen Martynov

Reputation: 20130

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

Upvotes: 1

abdoulayeYATERA
abdoulayeYATERA

Reputation: 209

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

Upvotes: 7

Rüdiger
Rüdiger

Reputation: 1763

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.

Upvotes: 0

Related Questions