Skip to content

Commit

Permalink
GitHub workflow: androidTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Binnette committed Nov 26, 2024
1 parent 803f57c commit 8e48ee2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 37 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ jobs:
- name: Run unit tests and jacoco coverage
run: ./gradlew testDebugUnitTest jacocoTestReport --stacktrace

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run connected tests
uses: ReactiveCircus/[email protected]
with:
api-level: 26
script: |
adb logcat &
./gradlew connectedCheck --no-parallel
- name: Coveralls GitHub Action
uses: coverallsapp/[email protected]
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static androidx.test.espresso.action.ViewActions.longClick;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static net.osmtracker.util.LogcatHelper.checkLogForMessage;
import static net.osmtracker.util.TestUtils.checkToastIsShownWith;
import static net.osmtracker.util.TestUtils.getLayoutsDirectory;
import static net.osmtracker.util.TestUtils.getStringResource;
Expand All @@ -34,6 +33,9 @@

public class DeleteLayoutTest {

@Rule
public GrantPermissionRule storagePermission = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE);

@Rule
public ActivityTestRule<ButtonsPresets> mRule = new ActivityTestRule(ButtonsPresets.class) {
@Override
Expand Down Expand Up @@ -75,8 +77,6 @@ public void layoutDeletionTest(){

deleteLayout(layoutName);

checkLogForMessage("TOAST", TestUtils.getStringResource(R.string.buttons_presets_successful_delete));

// Check the informative Toast is shown
checkToastIsShownWith(getStringResource(R.string.buttons_presets_successful_delete));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static junit.framework.TestCase.fail;
import static net.osmtracker.util.LogcatHelper.checkLogForMessage;
import static net.osmtracker.util.WaitForView.waitForView;

import android.Manifest;
Expand Down Expand Up @@ -44,9 +43,7 @@ public class DownloadLayoutTest {
@Rule
public GrantPermissionRule coarseLocationPermission = GrantPermissionRule.grant(Manifest.permission.ACCESS_COARSE_LOCATION);
@Rule
public GrantPermissionRule backgroundLocationPermission = GrantPermissionRule.grant(Manifest.permission.ACCESS_BACKGROUND_LOCATION);
@Rule
public GrantPermissionRule serviceLocationPermission = GrantPermissionRule.grant(Manifest.permission.FOREGROUND_SERVICE_LOCATION);
public GrantPermissionRule writeStoragePermission = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE);

@Rule
public ActivityTestRule<TrackManager> mRule = new ActivityTestRule(TrackManager.class) {
Expand Down Expand Up @@ -140,8 +137,6 @@ private void clickButtonsToDownloadLayout(String layoutName) {
onView(withText(TestUtils.getStringResource(R.string.available_layouts_description_dialog_positive_confirmation))).
perform(click());

checkLogForMessage("TOAST", TestUtils.getStringResource(R.string.available_layouts_successful_download));

TestUtils.checkToastIsShownWith(TestUtils.getStringResource(R.string.available_layouts_successful_download));
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package net.osmtracker.layouts;

import androidx.test.espresso.Espresso;
import androidx.test.espresso.ViewAssertion;
import androidx.test.rule.ActivityTestRule;

import net.osmtracker.OSMTracker;
import net.osmtracker.R;
import net.osmtracker.activity.AvailableLayouts;
import net.osmtracker.util.TestUtils;

import org.hamcrest.Matcher;
import org.junit.Rule;
import org.junit.Test;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.clearText;
import static androidx.test.espresso.action.ViewActions.click;
Expand All @@ -24,11 +12,21 @@
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static net.osmtracker.util.LogcatHelper.checkLogForMessage;
import static net.osmtracker.util.TestUtils.checkToastIsShownWith;
import static net.osmtracker.util.TestUtils.getStringResource;
import static org.hamcrest.core.IsNot.not;

import androidx.test.espresso.ViewAssertion;
import androidx.test.rule.ActivityTestRule;

import net.osmtracker.OSMTracker;
import net.osmtracker.R;
import net.osmtracker.activity.AvailableLayouts;

import org.hamcrest.Matcher;
import org.junit.Rule;
import org.junit.Test;

public class RepositorySettingsDialogTest {

@Rule
Expand Down Expand Up @@ -68,7 +66,7 @@ public void checkStateAfterToggle(int expectedActiveId, int expectedInactiveId){
onView(withId(expectedInactiveId)).check(matches(isEnabled()));
}

public void checkRepositoryValidity(String user, String repo, String branch, boolean isValid){
public void checkRepositoryValidity(String user, String repo, String branch, boolean isValid) {
onView(withId(R.id.github_config)).perform(click());

onView(withId(R.id.custom_server)).perform(click(), closeSoftKeyboard());
Expand All @@ -82,13 +80,10 @@ public void checkRepositoryValidity(String user, String repo, String branch, boo
String expectedMessage = (isValid) ? getStringResource(R.string.github_repository_settings_valid_server) :
getStringResource(R.string.github_repository_settings_invalid_server);

checkLogForMessage("TOAST", expectedMessage);

checkToastIsShownWith(expectedMessage);

ViewAssertion expectedDialogState = (isValid) ? doesNotExist() : matches(isDisplayed());
checkDialogState(expectedDialogState);

}

/**
Expand Down
16 changes: 5 additions & 11 deletions app/src/androidTest/java/net/osmtracker/util/TestUtils.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package net.osmtracker.util;

import static net.osmtracker.util.LogcatHelper.checkLogForMessage;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.preference.PreferenceManager;

import androidx.test.platform.app.InstrumentationRegistry;

import net.osmtracker.OSMTracker;
Expand All @@ -15,11 +16,6 @@
import java.io.FileWriter;
import java.util.ArrayList;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

/**
* Contains common and reusable static methods used for tests
*/
Expand Down Expand Up @@ -121,10 +117,8 @@ public static File getLayoutsDirectory(){
public static void checkToastIsShownWith(String text){
// Espresso can not check Toast for android >= 11
// https://github.com/android/android-test/issues/803
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
onView(withText(text)).inRoot(new ToastMatcher())
.check(matches(isDisplayed()));
}
//onView(withText(text)).inRoot(new ToastMatcher()).check(matches(isDisplayed()));
checkLogForMessage("TOAST", text);
}

public static String getStringResource(int resourceId){
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>

<!-- External storage permissions -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:description="@string/app_description"
android:icon="@drawable/ic_launcher"
Expand Down

0 comments on commit 8e48ee2

Please sign in to comment.