Skip to content

Commit caed5f3

Browse files
committed
Fix tests
1 parent e71044a commit caed5f3

7 files changed

Lines changed: 47 additions & 16 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
- name: run ui tests
6060
uses: reactivecircus/android-emulator-runner@v2.32.0
6161
with:
62-
api-level: 29
62+
api-level: 35
6363
script: ./gradlew :app:connectedDebugAndroidTest
6464

6565
- name: upload ui tests report

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ android {
1010
applicationId 'com.italankin.fifteen'
1111
versionCode 47
1212
versionName "1.15.5"
13-
minSdkVersion 19
13+
minSdkVersion 21
1414
targetSdkVersion 35
1515

1616
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -65,8 +65,8 @@ android {
6565
dependencies {
6666
testImplementation 'junit:junit:4.12'
6767

68-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
69-
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
70-
androidTestImplementation 'androidx.test:runner:1.4.0'
71-
androidTestImplementation 'androidx.test:rules:1.4.0'
68+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'
69+
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
70+
androidTestImplementation 'androidx.test:runner:1.7.0'
71+
androidTestImplementation 'androidx.test:rules:1.7.0'
7272
}

app/src/androidTest/java/com/italankin/fifteen/HoverTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
package com.italankin.fifteen;
22

3-
import static androidx.test.espresso.Espresso.onView;
4-
import static androidx.test.espresso.assertion.ViewAssertions.matches;
5-
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
6-
import static androidx.test.espresso.matcher.ViewMatchers.withId;
7-
83
import android.content.SharedPreferences;
9-
104
import androidx.test.ext.junit.rules.ActivityScenarioRule;
115
import androidx.test.ext.junit.runners.AndroidJUnit4;
126
import androidx.test.filters.LargeTest;
13-
147
import com.italankin.fifteen.game.ClassicGame;
158
import com.italankin.fifteen.game.Game;
9+
import com.italankin.fifteen.util.CreateNewGameAction;
1610
import com.italankin.fifteen.util.HoverSolveAction;
17-
1811
import org.junit.Assert;
1912
import org.junit.Before;
2013
import org.junit.Rule;
@@ -24,6 +17,11 @@
2417
import java.util.Arrays;
2518
import java.util.List;
2619

20+
import static androidx.test.espresso.Espresso.onView;
21+
import static androidx.test.espresso.assertion.ViewAssertions.matches;
22+
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
23+
import static androidx.test.espresso.matcher.ViewMatchers.withId;
24+
2725
@RunWith(AndroidJUnit4.class)
2826
@LargeTest
2927
public class HoverTest {
@@ -56,6 +54,9 @@ public void test() {
5654
9, 13, 2, 10, 1, 5, 11, 7, 3, 1,
5755
5, 2, 10, 9, 13, 14, 15, 11, 7, 6,
5856
4, 7, 6, 3, 2, 6, 7, 8, 12);
57+
58+
onView(withId(R.id.game_view)).perform(new CreateNewGameAction());
59+
5960
Game game = GameState.get().game;
6061

6162
onView(withId(R.id.game_view)).perform(new HoverSolveAction(game, solution));

app/src/androidTest/java/com/italankin/fifteen/SolveGameTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.italankin.fifteen.game.Game;
99
import com.italankin.fifteen.game.SnakeGame;
1010
import com.italankin.fifteen.game.SpiralGame;
11+
import com.italankin.fifteen.util.CreateNewGameAction;
1112
import com.italankin.fifteen.util.HoverSolveAction;
1213
import org.junit.Assert;
1314
import org.junit.Before;
@@ -47,6 +48,7 @@ public void classic() {
4748
)));
4849

4950
onView(withId(R.id.game_view)).check(matches(isDisplayed()));
51+
onView(withId(R.id.game_view)).perform(new CreateNewGameAction());
5052

5153
List<Integer> solution = Arrays.asList(
5254
2, 15, 9, 12, 1, 5, 12, 8, 4, 9,
@@ -69,6 +71,7 @@ public void snake() {
6971
)));
7072

7173
onView(withId(R.id.game_view)).check(matches(isDisplayed()));
74+
onView(withId(R.id.game_view)).perform(new CreateNewGameAction());
7275

7376
List<Integer> solution = Arrays.asList(
7477
4, 1, 6, 12, 9, 4, 1, 6, 7, 5, 12, 3,
@@ -89,6 +92,7 @@ public void spiral() {
8992
)));
9093

9194
onView(withId(R.id.game_view)).check(matches(isDisplayed()));
95+
onView(withId(R.id.game_view)).perform(new CreateNewGameAction());
9296

9397
List<Integer> solution = Arrays.asList(
9498
5, 2, 3, 5, 7, 12, 4, 1, 10, 14, 12, 4,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.italankin.fifteen.util;
2+
3+
import android.view.View;
4+
import androidx.test.espresso.UiController;
5+
import androidx.test.espresso.ViewAction;
6+
import androidx.test.espresso.matcher.ViewMatchers;
7+
import com.italankin.fifteen.GameSurface;
8+
import org.hamcrest.Matcher;
9+
10+
public class CreateNewGameAction implements ViewAction {
11+
12+
@Override
13+
public Matcher<View> getConstraints() {
14+
return ViewMatchers.isAssignableFrom(GameSurface.class);
15+
}
16+
17+
@Override
18+
public String getDescription() {
19+
return "Create new game";
20+
}
21+
22+
@Override
23+
public void perform(UiController uiController, View view) {
24+
((GameSurface) view).createNewGame(false);
25+
}
26+
}

app/src/main/java/com/italankin/fifteen/GameSurface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public void updateViews() {
446446
mHardModeView.update();
447447
}
448448

449-
private void createNewGame(boolean isUser) {
449+
public void createNewGame(boolean isUser) {
450450
if (Settings.newGameDelay && ((System.currentTimeMillis() - lastSolvedTimestamp) < Constants.NEW_GAME_DELAY)) {
451451
return;
452452
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
android.nonFinalResIds=false
22
android.nonTransitiveRClass=false
3-
android.useAndroidX=false
3+
android.useAndroidX=true

0 commit comments

Comments
 (0)