简体   繁体   中英

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?

在此处输入图片说明

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

You need to change Project layout from Android to Project : 当前布局

选择其他布局

新版面

And now you can easily create folders from Android Studio UI

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. eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM