Skip to content

Commit 28890be

Browse files
committed
Parameterize tests by devices.
1 parent 3984a6c commit 28890be

File tree

5 files changed

+71
-20
lines changed

5 files changed

+71
-20
lines changed

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<mdep.analyze.skip>true</mdep.analyze.skip>
3131

3232
<!-- Dependencies. -->
33-
<org.junit.version>5.11.1</org.junit.version>
33+
<org.junit.version>6.0.1</org.junit.version>
3434
<io.appium.version>10.0.0</io.appium.version>
3535
</properties>
3636

@@ -84,6 +84,10 @@
8484
<groupId>org.junit.platform</groupId>
8585
<artifactId>junit-platform-launcher</artifactId>
8686
</dependency>
87+
<dependency>
88+
<groupId>org.junit.jupiter</groupId>
89+
<artifactId>junit-jupiter-params</artifactId>
90+
</dependency>
8791

8892
<dependency>
8993
<groupId>com.io7m.jmulticlose</groupId>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.thepalaceproject.ait;
2+
3+
/**
4+
* A single device configuration.
5+
*
6+
* @param deviceName The device name. For example, "Samsung Galaxy S22".
7+
* @param osVersion The OS version. For example, "12.0".
8+
*/
9+
10+
public record AppiumDeviceConfiguration(
11+
String deviceName,
12+
String osVersion)
13+
{
14+
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.thepalaceproject.ait;
2+
3+
import java.util.stream.Stream;
4+
5+
/**
6+
* The set of device configurations we use to run each test.
7+
*/
8+
9+
public final class AppiumDeviceConfigurations
10+
{
11+
private AppiumDeviceConfigurations()
12+
{
13+
14+
}
15+
16+
public static Stream<AppiumDeviceConfiguration> deviceConfigurations()
17+
{
18+
return Stream.of(
19+
new AppiumDeviceConfiguration(
20+
"Samsung Galaxy S22",
21+
"12.0"
22+
)
23+
);
24+
}
25+
}

src/main/java/org/thepalaceproject/ait/AppiumTestContext.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,39 @@ private AppiumTestContext(
3030
}
3131

3232
public static AppiumTestContext createForTestInfo(
33-
final TestInfo testInfo)
33+
final TestInfo testInfo,
34+
final AppiumDeviceConfiguration deviceConfiguration)
3435
throws Exception
3536
{
36-
return create(AppiumTestContext.createTestName(testInfo));
37+
return create(
38+
AppiumTestContext.createTestName(testInfo),
39+
deviceConfiguration
40+
);
3741
}
3842

3943
public static AppiumTestContext create(
40-
final String testName)
44+
final String testName,
45+
final AppiumDeviceConfiguration deviceConfiguration)
4146
throws Exception
4247
{
4348
LOG.debug("Setting up Appium context...");
4449

4550
final var browserstackAppId =
4651
System.getenv("PALACE_BROWSERSTACK_APP_URL");
4752
if (browserstackAppId != null) {
48-
return createForBrowserstack(testName, browserstackAppId);
53+
return createForBrowserstack(
54+
testName,
55+
browserstackAppId,
56+
deviceConfiguration
57+
);
4958
}
5059
return createForLocal(testName);
5160
}
5261

5362
private static AppiumTestContext createForBrowserstack(
5463
final String testName,
55-
final String appId)
64+
final String appId,
65+
final AppiumDeviceConfiguration deviceConfiguration)
5666
throws Exception
5767
{
5868
final var resources =
@@ -81,8 +91,8 @@ private static AppiumTestContext createForBrowserstack(
8191
browserstackOptions.put("sessionName", testName);
8292

8393
final var caps = new DesiredCapabilities();
84-
caps.setCapability("appium:deviceName", "Samsung Galaxy S22");
85-
caps.setCapability("appium:os_version", "12.0");
94+
caps.setCapability("appium:deviceName", deviceConfiguration.deviceName());
95+
caps.setCapability("appium:os_version", deviceConfiguration.osVersion());
8696
caps.setCapability("appium:app", appId);
8797
caps.setCapability("platformName", "Android");
8898
caps.setCapability("bstack:options", browserstackOptions);
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
package org.thepalaceproject.ait;
22

33
import org.junit.jupiter.api.AfterEach;
4-
import org.junit.jupiter.api.BeforeEach;
54
import org.junit.jupiter.api.MethodOrderer;
6-
import org.junit.jupiter.api.Test;
75
import org.junit.jupiter.api.TestInfo;
86
import org.junit.jupiter.api.TestMethodOrder;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.MethodSource;
99

1010
@TestMethodOrder(MethodOrderer.DisplayName.class)
1111
public final class StartupTest
1212
{
1313
private AppiumTestContext context;
1414

15-
@BeforeEach
16-
public void setUp(
17-
final TestInfo testInfo)
18-
throws Exception
19-
{
20-
this.context = AppiumTestContext.createForTestInfo(testInfo);
21-
}
22-
2315
@AfterEach
2416
public void tearDown()
2517
throws Exception
2618
{
2719
this.context.close();
2820
}
2921

30-
@Test
31-
void testHelloWorld()
22+
@ParameterizedTest
23+
@MethodSource("org.thepalaceproject.ait.AppiumDeviceConfigurations#deviceConfigurations")
24+
void testHelloWorld(
25+
final AppiumDeviceConfiguration device,
26+
final TestInfo testInfo)
27+
throws Exception
3228
{
29+
this.context = AppiumTestContext.createForTestInfo(testInfo, device);
3330
SplashScreen.waitForAndCompleteSplashScreen(this.context);
3431
}
3532
}

0 commit comments

Comments
 (0)