Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Make unit tests work from CLI (#846)

Leendert de Borst9669307480a1
diff --git a/.github/workflows/mobile-app-build.yml b/.github/workflows/mobile-app-build.yml
index ca390c882..c652445f1 100644
--- a/.github/workflows/mobile-app-build.yml
+++ b/.github/workflows/mobile-app-build.yml
@@ -85,6 +85,12 @@ jobs:
--output-dir ./build \
--platform android
+ - name: Run tests
+ run: npm run test
+
+ - name: Run linting
+ run: npm run lint
+
- name: Setup Java
uses: actions/setup-java@v3
with:
@@ -97,15 +103,19 @@ jobs:
- name: Run Android Unit Tests
run: |
cd android
- ./gradlew testDebugUnitTest --tests "net.aliasvault.app.nativevaultmanager.*"
+ ./gradlew :app:testDebugUnitTest --tests "net.aliasvault.app.*"
+
+ - name: Upload Android Test Reports
+ if: always()
+ uses: actions/upload-artifact@v4
+ with:
+ name: android-test-reports
+ path: apps/mobile-app/android/app/build/reports/tests/testDebugUnitTest/
+ retention-days: 7
- name: Build Android App
run: |
cd android
./gradlew assembleDebug
- - name: Run tests
- run: npm run test
- - name: Run linting
- run: npm run lint
diff --git a/apps/mobile-app/android/app/build.gradle b/apps/mobile-app/android/app/build.gradle
index 7f2987933..9b2428ce1 100644
--- a/apps/mobile-app/android/app/build.gradle
+++ b/apps/mobile-app/android/app/build.gradle
@@ -135,6 +135,16 @@ android {
// Focus only on app/src and exclude expo modules
disable 'InvalidPackage'
}
+ testOptions {
+ unitTests.all {
+ useJUnitPlatform()
+ testLogging {
+ events "passed", "failed", "skipped"
+ exceptionFormat "full"
+ showStandardStreams true
+ }
+ }
+ }
}
// Apply static values from `gradle.properties` to the `android.packagingOptions`
@@ -176,6 +186,9 @@ dependencies {
testImplementation 'androidx.test:rules:1.5.0'
testImplementation 'androidx.test.ext:junit:1.1.5'
testImplementation 'org.robolectric:robolectric:4.9'
+ testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.2'
+ testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
+ testImplementation 'org.junit.vintage:junit-vintage-engine:5.9.2'
def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
diff --git a/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/AutofillTest.kt b/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/AutofillTest.kt
index dcf8acba4..1d6b26e68 100644
--- a/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/AutofillTest.kt
+++ b/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/AutofillTest.kt
@@ -17,13 +17,10 @@ import kotlin.test.assertTrue
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28], manifest = Config.NONE)
class AutofillTest {
- private lateinit var credentialMatcher: CredentialMatcher
private lateinit var testCredentials: List<Credential>
@Before
fun setup() {
- credentialMatcher = CredentialMatcher()
-
// Create test credentials
testCredentials = listOf(
createTestCredential(
@@ -56,7 +53,7 @@ class AutofillTest {
@Test
fun testExactUrlMatch() {
- val matches = credentialMatcher.filterCredentialsByAppInfo(
+ val matches = CredentialMatcher.filterCredentialsByAppInfo(
testCredentials,
"www.coolblue.nl",
)
@@ -67,7 +64,7 @@ class AutofillTest {
@Test
fun testBaseUrlMatch() {
- val matches = credentialMatcher.filterCredentialsByAppInfo(
+ val matches = CredentialMatcher.filterCredentialsByAppInfo(
testCredentials,
"https://gmail.com/signin",
)
@@ -78,7 +75,7 @@ class AutofillTest {
@Test
fun testRootDomainMatch() {
- val matches = credentialMatcher.filterCredentialsByAppInfo(
+ val matches = CredentialMatcher.filterCredentialsByAppInfo(
testCredentials,
"https://mail.google.com",
)
@@ -89,7 +86,7 @@ class AutofillTest {
@Test
fun testDomainNamePartMatch() {
- val matches = credentialMatcher.filterCredentialsByAppInfo(
+ val matches = CredentialMatcher.filterCredentialsByAppInfo(
testCredentials,
"https://coolblue.be",
)
@@ -101,7 +98,7 @@ class AutofillTest {
@Test
fun testPackageNameMatch() {
- val matches = credentialMatcher.filterCredentialsByAppInfo(
+ val matches = CredentialMatcher.filterCredentialsByAppInfo(
testCredentials,
"com.coolblue.app",
)
@@ -113,7 +110,7 @@ class AutofillTest {
@Test
fun testNoMatches() {
- val matches = credentialMatcher.filterCredentialsByAppInfo(
+ val matches = CredentialMatcher.filterCredentialsByAppInfo(
testCredentials,
"https://nonexistent.com",
)
@@ -123,7 +120,7 @@ class AutofillTest {
@Test
fun testInvalidUrl() {
- val matches = credentialMatcher.filterCredentialsByAppInfo(
+ val matches = CredentialMatcher.filterCredentialsByAppInfo(
testCredentials,
"not a url",
)
diff --git a/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/VaultStoreTest.kt b/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/VaultStoreTest.kt
index e808dc6ac..846fb9b73 100644
--- a/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/VaultStoreTest.kt
+++ b/apps/mobile-app/android/app/src/test/java/net/aliasvault/app/nativevaultmanager/VaultStoreTest.kt
@@ -117,7 +117,7 @@ class VaultStoreTest {
// Then, try to re-load the database and ensure the __EFMigrationsHistory table still exists.
// This asserts that the database commit results in a properly exported and encrypted database file.
- vaultStore.clearVault()
+ vaultStore.clearCache()
vaultStore.storeEncryptionKey(testEncryptionKeyBase64)
vaultStore.unlockVault()
diff --git a/docs/misc/dev/mobile-apps/android.md b/docs/misc/dev/mobile-apps/android.md
index d5d927086..bb78efb23 100644
--- a/docs/misc/dev/mobile-apps/android.md
+++ b/docs/misc/dev/mobile-apps/android.md
@@ -40,7 +40,7 @@ The Android project contains unit tests that test the `VaultStore` native Kotlin
In order to run the Android unit tests:
```
-./gradlew test
+./gradlew :app:testDebugUnitTest --tests "net.aliasvault.app.*"
```
You can also open up the project in Android Studio, navigate to the `VaultStoreTest.kt` file and run/debug individual tests.