Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

unit testing - Jvm options in android when run gradlew test

I have a project that using Robolectric for unit test purpose. This project uses Robolectric 3.0 and need to add -ea and -noverify options in Virtual Machine options.

In Android Studio, I created new JUnit configuration in Run > Edit Configurations... and then set VM Options to -ea -noverify. With this way I success to run my unit test. This is image about my configure, view Here

However, for continuous deployment, I need run unit test with command line. So I use ./gradlew test to run unit test. I also add org.gradle.jvmargs=-ea -noverify to gradle.properties file. Unfortunately, it doesn't work. I can run unit test but I got java.lang.VerifyError and I think that gradle.properties was not load.

So, my question is, how to make gradle.properties load or do you know any way to fix my vm options problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is already answered but this may be an easier solution:

In your application modules' build.gradle file in android closure, add this.

android {
  ....

  testOptions {
    unitTests.all {
      jvmArgs '-noverify'
    }
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...