The gradlew test commands fails on CircleCI. When I execute the same command locally it works fine and all the test cases are passed. I am attaching yml file, logs from CircleCI and my test class.
Here is my yml file.
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
When I check the logs for CircleCI, these are the logs :
Executing transform IdentityTransform -> IdentityTransform on artifact core.jar (com.google.zxing:core:3.3.0) Executing transform IdentityTransform -> IdentityTransform on artifact protobuf-java.jar (com.google.protobuf:protobuf-java:2.6.1) Executing transform IdentityTransform -> IdentityTransform on artifact backport-util-concurrent.jar (backport-util-concurrent:backport-util-concurrent:3.1) Executing transform IdentityTransform -> IdentityTransform on artifact xercesMinimal.jar (nekohtml:xercesMinimal:1.9.6.2) Executing transform IdentityTransform -> IdentityTransform on artifact nekohtml.jar (nekohtml:nekohtml:1.9.6.2) Executing transform MockableJarTransform on file /opt/android/sdk/platforms/android-28/android.jar Starting process 'Gradle Test Executor 2'. Working directory: /home/circleci/code/app Command: /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' Successfully started process 'Gradle Test Executor 2'
com.mindvalley.mva.loginmodule.LoginActivityTest > isSkipLoginVisible STANDARD_OUT [Robolectric] com.mindvalley.mva.loginmodule.LoginActivityTest.isSkipLoginVisible: sdk=28; resources=binary Called loadFromPath(/system/framework/framework-res.apk, true); mode=binary sdk=28
com.mindvalley.mva.loginmodule.LoginActivityTest > isSkipLoginVisible SKIPPED
Task :app:testInternalReleaseUnitTest FAILED :app:testInternalReleaseUnitTest (Thread[Task worker for ':' Thread 2,5,main]) completed. Took 3.413 secs.
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:testInternalReleaseUnitTest'.
Process 'Gradle Test Executor 2' finished with non-zero exit value 137 This problem might be caused by incorrect test process configuration. Please refer to the test execution section in the user guide at https://docs.gradle.org/4.10.1/userguide/java_plugin.html#sec:test_execution
Try: Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
My 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 = "[email protected]";
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 = "[email protected]";
password = "";
Assert.assertTrue(!activity.sanitizeLogin(email, password));
email = "[email protected]";
password = "test";
Assert.assertTrue(!activity.sanitizeLogin(email, password));
email = "[email protected]";
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("[email protected]");
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;
}
}