简体   繁体   English

无法在Android Studio中为robolectric创建“测试”文件夹

[英]cannot create “test” folder in android studio for robolectric

I want to add robolectric tests to my project in intellij. 我想在我的intellij项目中添加robolectric测试。

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 并且不要忘记将其写入应用程序模块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 : 您需要将项目布局从Android更改为Project 当前布局

选择其他布局

新版面

And now you can easily create folders from Android Studio UI 现在,您可以轻松地从Android Studio用户界面创建文件夹

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. Android Studio已更改,不再需要使用Build Variants来区分UnitTest和AndroidTests。

Just create the TestFolders manually. 只需手动创建TestFolders。 eg app/scr/androidTest and put your test Files there. 例如app/scr/androidTest并将您的测试文件放在此处。

Maybe just create a new Project with android Studio. 也许只是使用android Studio创建一个新项目。 The Folders for tests will be atomatically created, you'll see what i mean. 测试文件夹将自动创建,您将明白我的意思。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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