CircleCI ./gradlew测试命令失败

时间:2019-02-04 10:15:17

标签: android gradle android-testing robolectric circleci

gradlew测试命令在CircleCI上失败。 当我在本地执行同一命令时,它工作正常,并且所有测试用例都通过了。 我要附加yml文件,CircleCI和测试类的日志。

这是我的yml文件。

version: 2
jobs:
  build:
    working_directory: ~/code
    docker:
    - image: circleci/android:api-28
    environment:
      JVM_OPTS: -Xmx4096m
      CC_TEST_REPORTER_ID: XXXXXXXXXXXXXXXXXX
    steps:
    - checkout
    - restore_cache:
        key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
    #      - run:
    #         name: Chmod permissions #if permission for Gradlew Dependencies fail, use this.
    #         command: sudo chmod +x ./gradlew
    - run:
        name: Download Dependencies
        command: ./gradlew androidDependencies
    - save_cache:
        paths:
        - ~/.gradle
        key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
#    - run:
#        name: Run Lint Tests
#        command: ./gradlew lint test
    - run:
        name: Run Tests
        command: ./gradlew test --info

#    - run:
#        name: Run Instrument Tests
#        command: ./gradlew connectedAndroidTest

    - store_artifacts: # for display in Artifacts: https://circleci.com/docs/2.0/artifacts/
        path: app/build/reports
        destination: reports
    - store_test_results: # for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/
        path: app/build/test-results

当我查看CircleCI的日志时,这些是日志:

  
    

在工件上执行转换IdentityTransform-> IdentityTransform     core.jar(com.google.zxing:core:3.3.0)执行转换     IdentityTransform->工件protobuf-java.jar上的IdentityTransform     (com.google.protobuf:protobuf-java:2.6.1)执行转换     IdentityTransform->工件上的IdentityTransform     backport-util-concurrent.jar     (backport-util-concurrent:backport-util-concurrent:3.1)执行     在工件上转换IdentityTransform-> IdentityTransform     xercesMinimal.jar(nekohtml:xercesMinimal:1.9.6.2)执行转换     IdentityTransform->工件nekohtml.jar上的IdentityTransform     (nekohtml:nekohtml:1.9.6.2)执行转换MockableJarTransform     在文件/opt/android/sdk/platforms/android-28/android.jar上     处理“等级测试执行器2”。工作目录:     / home / circleci / code / app命令:     / usr / lib / jvm / java-8-openjdk-amd64 / bin / java -Djava.awt.headless = true     -Djava.security.manager = worker.org.gradle.process.internal.worker.child.BootstrapSecurityManager     -Dorg.gradle.native = false -noverify -Dfile.encoding = UTF-8 -Duser.country -Duser.language = en -Duser.variant -ea -cp /home/circleci/.gradle/caches/4.10.1/ workerMain / gradle-worker.jar     worker.org.gradle.process.internal.worker.GradleWorkerMain'Gradle     Test Executor 2'成功启动过程“ Gradle Test Executor 2”

         

com.mindvalley.mva.loginmodule.LoginActivityTest> isSkipLoginVisible     STANDARD_OUT         [Robolectric] com.mindvalley.mva.loginmodule.LoginActivityTest.isSkipLoginVisible:     sdk = 28;资源=二进制         称为loadFromPath(/system/framework/framework-res.apk,true); mode = binary sdk = 28

         

com.mindvalley.mva.loginmodule.LoginActivityTest> isSkipLoginVisible     跳过

         
      

任务:app:testInternalReleaseUnitTest失败:app:testInternalReleaseUnitTest(线程[任务工作者为':'线程       2,5,main])已完成。花了3.413秒。

    
         

失败:构建失败,并出现异常。

         
        
  • 出了什么问题:任务':app:testInternalReleaseUnitTest'的执行失败。

             
          

    进程'Gradle Test Executor 2'完成,退出值非零137此问题可能是由错误的测试过程引起的       组态。请参阅       用户指南位于       https://docs.gradle.org/4.10.1/userguide/java_plugin.html#sec:test_execution

        
  •     
  • 尝试:使用--stacktrace选项运行以获取堆栈跟踪。使用--debug选项运行,以获取更多日志输出。使用--scan运行以获取     全面的见解。

  •     
  • https://help.gradle.org

  • 获得更多帮助     
  

我的LoginTestActivity

@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, application = MockApplication.class)
public class LoginActivityTest {

    private LoginActivity activity;

    @Before
    public void setup() {
        activity = Robolectric.buildActivity(LoginActivity.class).create().resume().get();
    }

    @Test
    public void shouldNotBeNull() {
        Assert.assertNotNull(activity);
    }

    /**
     * check by default visibility. It should be not visible
     * Once we change variable in Login module it should be Visible
     */
    @Test
    public void isSkipLoginVisible() {
        TextView skipLogin = activity.findViewById(com.mindvalley.loginmodule.R.id.skip_login);
        LoginModule.getInstance().setSkipLogin(false);
        activity.setSkipLoginVisibility();
        Assert.assertTrue(skipLogin.getVisibility() == View.GONE);
        LoginModule.getInstance().setSkipLogin(true);
        activity.setSkipLoginVisibility();
        Assert.assertTrue( skipLogin.getVisibility() == View.VISIBLE);
    }

    @Test
    public void enableActionButtonTest() {
        CustomFeedbackText loginButton = activity.findViewById(com.mindvalley.loginmodule.R.id.login_btn_login);
        String email = "";
        String password = "";
        activity.enableActionButton(email, password);
        Assert.assertTrue(!loginButton.isEnabled());
        email = "harsh@mindvalley.com";
        password = "123";
        activity.enableActionButton(email, password);
        Assert.assertTrue(loginButton.isEnabled());
    }

    @Test
    public void skipLoginClicked() {
        TextView skipLogin = activity.findViewById(com.mindvalley.loginmodule.R.id.skip_login);
        Assert.assertTrue(!PreferenceManager.getBoolean(LoginModule.SKIP_LOGIN, false));
        skipLogin.performClick();
        Assert.assertTrue(PreferenceManager.getBoolean(LoginModule.SKIP_LOGIN, false));
    }

    @Test
    public void sanitizeLogin() {
        String email = "";
        String password = "";
        Assert.assertTrue(!activity.sanitizeLogin(email, password));
        email = "harsh";
        password = "";
        Assert.assertTrue(!activity.sanitizeLogin(email, password));
        email = "harsh@mindvalley";
        password = "";
        Assert.assertTrue(!activity.sanitizeLogin(email, password));
        email = "harsh@mindvalley.com";
        password = "";
        Assert.assertTrue(!activity.sanitizeLogin(email, password));
        email = "harsh@mindvalley.com";
        password = "test";
        Assert.assertTrue(!activity.sanitizeLogin(email, password));
        email = "harsh@mindvalley.com";
        password = "test123";
        Assert.assertTrue(activity.sanitizeLogin(email, password));
    }

    @Test
    public void loginClicked() {
        CustomFeedbackText loginButton = activity.findViewById(com.mindvalley.loginmodule.R.id.login_btn_login);
        EditText emailEditText = activity.findViewById(com.mindvalley.loginmodule.R.id.login_edittext_email);
        EditText passwordEditText = activity.findViewById(com.mindvalley.loginmodule.R.id.login_edittext_password);
        emailEditText.setText("harsh@mindvalley.com");
        passwordEditText.setText("test123");
        loginButton.performClick();
        Assert.assertTrue(Util_Auth0.getInstance().getAndroidClient() != null);
        // test update prefs method
        activity.updatePrefs();
        Assert.assertTrue(!PreferenceManager.getBoolean(LoginModule.SKIP_LOGIN, false));
        Assert.assertTrue(PreferenceManager.getBoolean(LoginModule.SIGNED_IN, false));
    }

    @After
    public void tearDown() {
        activity = null;
    }
}

1 个答案:

答案 0 :(得分:1)

在这里得到答案

https://github.com/robolectric/robolectric/issues/4591#event-2116260870

这里是stackoverflow答案Why are my Gradle builds dying with exit-code 137?

的链接

感谢克里斯蒂安·威廉姆斯