Skip to content

Commit

Permalink
Test NoteMapper helper with JUnit 5/Jupiter.
Browse files Browse the repository at this point in the history
Our very first unit tests!

Needs some additional plugins, because Google isn't moving on JUnit 5 support.
see
- Google tracking issue:
  android/android-test#224
- Android <-> JUnit 5 plugin
  https://github.com/mannodermaus/android-junit5
- StackOverflow answer about the plugin
  https://stackoverflow.com/questions/46161113/junit-5-for-android-testing
  • Loading branch information
Jules Kerssemakers committed Sep 10, 2023
1 parent b49495e commit 2ff0211
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'de.mannodermaus.android-junit5'

android {
compileSdkVersion 33
Expand Down Expand Up @@ -51,6 +52,8 @@ dependencies {
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.preference:preference:1.2.0'
implementation "androidx.annotation:annotation:1.6.0"

testImplementation "org.junit.jupiter:junit-jupiter:5.9.2"
}

// Not sure why this started happening all of a sudden, but the buidl was failing
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.nicobrailo.pianoli.melodies;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static com.nicobrailo.pianoli.melodies.NoteMapper.get_key_idx_from_note;
import static org.junit.jupiter.api.Assertions.*;

class NoteMapperTest {

@Test
public void noteRangeLimits() {
assertEquals(0, get_key_idx_from_note("C1"),
"lowest parsable note should be parsed");
assertEquals(26, get_key_idx_from_note("B2"),
"lowest parsable note should be parsed");

}

@ParameterizedTest
@ValueSource(strings = {"C#1", "Db1", "D♭1"})
public void fancySynonyms(String note) {
assertEquals(1, get_key_idx_from_note(note),
"all synonyms for the same note should work, including fancy symbols");
}
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {

dependencies {
classpath 'com.android.tools.build:gradle:8.0.2'
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.9.3.0"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit 2ff0211

Please sign in to comment.