Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update automated tests #52

Merged
merged 5 commits into from
Aug 23, 2023
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
57 changes: 57 additions & 0 deletions .github/workflows/android-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Android Emulator Tests
on: [ push, pull_request ]

jobs:
connected-tests:
runs-on: macos-latest
strategy:
matrix:
api-level: [32]
target: [google_apis]
arch: [x86_64]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Set up JDK environment
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Gradle cache
uses: gradle/gradle-build-action@v2

- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}

- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
arch: ${{ matrix.arch }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: Run connected tests
uses: ReactiveCircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
arch: ${{ matrix.arch }}
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: ./gradlew :app:connectedCheck
25 changes: 21 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
name: Build
on: [push, pull_request]
name: Build Test
on: [ push, pull_request ]

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Set up JDK environment
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

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

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Run local unit tests
run: bash ./gradlew test --stacktrace

- name: Build the app
run: ./gradlew build
run: bash ./gradlew build --stacktrace
12 changes: 12 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,15 @@ dependencies {
}
}
}

tasks.withType(Test) {
testLogging {
events "passed", "skipped", "failed", "standard_out"
exceptionFormat "full"
afterSuite { desc, result ->
if (!desc.parent) {
println("\nResult: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)\n")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.secuso.privacyfriendlypasswordgenerator;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.secuso.privacyfriendlypasswordgenerator.generator.PasswordGenerator;
import org.secuso.privacyfriendlypasswordgenerator.generator.PasswordGeneratorTask;

import java.util.concurrent.CountDownLatch;

public class PasswordGeneratorTaskTest {
@Test
public void testPasswordGeneratorTaskWithRandomValues() throws InterruptedException {
int numTests = 10;
final CountDownLatch signal = new CountDownLatch(numTests);
for (int i = 0; i < numTests; i++) {
PasswordGenerator generator = new PasswordGenerator(
"test1", "test2", Integer.toString(i), "test4", 5, 1000, "SHA256", "10"
);
String expected = generator.getPassword(1, 1, 1, 1, 16);
new PasswordGeneratorTask() {
@Override
protected void onPostExecute(String s) {
assertEquals(expected, s);
signal.countDown();
}
}.execute(new PasswordGeneratorTask.PasswordGeneratorParameter(
"test1", "test2", Integer.toString(i), "test4", 5, 1000, "SHA256", "10",
1, 1, 1, 1, 16
));
}
signal.await();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import org.junit.Test;
import org.secuso.privacyfriendlypasswordgenerator.generator.PasswordGenerator;
import org.secuso.privacyfriendlypasswordgenerator.generator.PasswordGeneratorTask;

import java.util.concurrent.CountDownLatch;

/**
* Tests the PasswordGenerator
Expand Down Expand Up @@ -101,29 +98,6 @@ public void testPasswordGeneratorWithSpecifiedValues() {
assertArrayEquals(expectedPasswords, generatedPasswords);
}

@Test
public void testPasswordGeneratorTaskWithRandomValues() throws InterruptedException {
int numTests = 10;
final CountDownLatch signal = new CountDownLatch(numTests);
for (int i = 0; i < numTests; i++) {
PasswordGenerator generator = new PasswordGenerator(
"test1", "test2", Integer.toString(i), "test4", 5, 1000, "SHA256", "10"
);
String expected = generator.getPassword(1, 1, 1, 1, 16);
new PasswordGeneratorTask() {
@Override
protected void onPostExecute(String s) {
assertEquals(expected, s);
signal.countDown();
}
}.execute(new PasswordGeneratorTask.PasswordGeneratorParameter(
"test1", "test2", Integer.toString(i), "test4", 5, 1000, "SHA256", "10",
1, 1, 1, 1, 16
));
}
signal.await();
}

private PasswordGenerator getDefaultGenerator() {
return new PasswordGenerator("test.com",
"hugo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void testEncode() {
try {
expected = "testü".getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
assertTrue(false);
fail();
expected = "testü".getBytes();
}
byte[] converted = UTF8.encode("testü");
Expand Down