Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/android-instrumented-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Android Instrumented Tests

on:
push:
pull_request:

jobs:
instrumented-tests:
runs-on: ubuntu-latest
timeout-minutes: 35

env:
GRADLE_OPTS: -Xmx4g
ADB_INSTALL_TIMEOUT: 15

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Make gradlew executable
run: chmod +x gradlew

- name: Show disk space
run: df -h

- name: Create emulator wait script
run: |
cat > wait-for-android.sh <<'EOF'
#!/usr/bin/env bash
set -e

adb wait-for-device

echo "Waiting for boot completion..."

until adb shell getprop sys.boot_completed | grep -m 1 '1'; do
sleep 5
done

echo "Boot completed"

until adb shell getprop ro.build.version.sdk | grep -E '^[0-9]+$'; do
echo "Waiting for SDK..."
sleep 5
done

echo "SDK ready"

until adb shell pm path android >/dev/null 2>&1; do
echo "Waiting for PackageManager..."
sleep 5
done

echo "PackageManager ready"
EOF

chmod +x wait-for-android.sh

- name: Run connected tests
uses: ReactiveCircus/android-emulator-runner@v2
with:
api-level: 29
arch: x86_64
target: default
profile: pixel_4

emulator-boot-timeout: 900

disable-spellchecker: true

emulator-options: >-
-no-window
-gpu swiftshader_indirect
-noaudio
-no-boot-anim
-camera-back none
-camera-front none
-no-snapshot
-memory 2048

script: |
./wait-for-android.sh
adb shell getprop ro.build.version.sdk
./gradlew connectedDebugAndroidTest --stacktrace --no-daemon
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -44,7 +45,7 @@ public static void beforeAll() throws IOException {

try (InputStream inputStream = assets.open("test_image.jpg")) {
try (FileOutputStream outputStream = new FileOutputStream(testFile)) {
byte[] imageBytes = inputStream.readAllBytes();
byte[] imageBytes = readAllBytes(inputStream);
testFileSize = imageBytes.length;

outputStream.write(imageBytes);
Expand Down Expand Up @@ -90,4 +91,17 @@ public static Uri getImageContentUri(Context context, File imageFile, int size)

return contentResolver.insert(imagesCollection, values);
}

private static byte[] readAllBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();

int bytesRead;
byte[] data = new byte[16384];

while ((bytesRead = inputStream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, bytesRead);
}

return buffer.toByteArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import app.notesr.core.util.FilesUtils;
Expand Down Expand Up @@ -64,7 +64,7 @@ public void testGetThumbnail() throws IOException {

byte[] thumbnailBytes = thumbnailCreator.getThumbnail(Uri.fromFile(imageFile));

Files.write(Path.of(thumbnailFile.getAbsolutePath()), thumbnailBytes);
Files.write(Paths.get(thumbnailFile.getAbsolutePath()), thumbnailBytes);

Size imageSize = getImageSize(imageFile);
Size thumbnailSize = getImageSize(thumbnailFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class VideoThumbnailCreatorTest extends ThumbnailCreatorTestBase {
private static final int EXPECTED_WIDTH = 200;
Expand All @@ -34,7 +34,7 @@ public void testGetThumbnail() throws IOException {
byte[] thumbnailBytes = thumbnailCreator.getThumbnail(Uri.fromFile(videoFile));
assertNotNull("Thumbnail creator returned null", thumbnailBytes);

Files.write(Path.of(thumbnailFile.getAbsolutePath()), thumbnailBytes);
Files.write(Paths.get(thumbnailFile.getAbsolutePath()), thumbnailBytes);

int actualWidth = getImageSize(thumbnailFile).getWidth();

Expand Down
Loading