Skip to content

Commit da326d6

Browse files
test: Run tests on the JUnit Jupiter Platform (#1721)
1 parent 3127fda commit da326d6

File tree

69 files changed

+429
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+429
-424
lines changed

build.gradle

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ dependencies {
5757
implementation 'commons-io:commons-io:2.11.0'
5858
implementation 'org.slf4j:slf4j-api:1.7.36'
5959

60-
testImplementation 'junit:junit:4.13.2'
60+
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0'
6161
testImplementation 'org.hamcrest:hamcrest:2.2'
6262
testImplementation (group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.2.1') {
6363
exclude group: 'org.seleniumhq.selenium'
@@ -192,7 +192,7 @@ processResources {
192192
}
193193

194194
task xcuiTest( type: Test ) {
195-
useJUnit()
195+
useJUnitPlatform()
196196
testLogging.showStandardStreams = true
197197
testLogging.exceptionFormat = 'full'
198198
filter {
@@ -207,7 +207,7 @@ task xcuiTest( type: Test ) {
207207
}
208208

209209
task uiAutomationTest( type: Test ) {
210-
useJUnit()
210+
useJUnitPlatform()
211211
testLogging.showStandardStreams = true
212212
testLogging.exceptionFormat = 'full'
213213
filter {
@@ -223,7 +223,7 @@ task uiAutomationTest( type: Test ) {
223223
}
224224

225225
task miscTest( type: Test ) {
226-
useJUnit()
226+
useJUnitPlatform()
227227
testLogging.showStandardStreams = true
228228
testLogging.exceptionFormat = 'full'
229229
filter {

src/test/java/io/appium/java_client/android/AndroidAbilityToUseSupplierTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import static io.appium.java_client.touch.WaitOptions.waitOptions;
55
import static io.appium.java_client.touch.offset.ElementOption.element;
66
import static java.time.Duration.ofSeconds;
7-
import static org.junit.Assert.assertNotEquals;
7+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
88

99
import io.appium.java_client.AppiumBy;
1010
import io.appium.java_client.functions.ActionSupplier;
1111
import io.appium.java_client.touch.offset.ElementOption;
12-
import org.junit.Test;
12+
import org.junit.jupiter.api.Test;
1313
import org.openqa.selenium.By;
1414
import org.openqa.selenium.Point;
1515
import org.openqa.selenium.WebElement;

src/test/java/io/appium/java_client/android/AndroidActivityTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
package io.appium.java_client.android;
1818

19-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
2020

2121
import io.appium.java_client.android.nativekey.AndroidKey;
2222
import io.appium.java_client.android.nativekey.KeyEvent;
23-
import org.junit.Before;
24-
import org.junit.Test;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2525

2626
public class AndroidActivityTest extends BaseAndroidTest {
2727

28-
@Before public void setUp() {
28+
@BeforeEach public void setUp() {
2929
Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
3030
driver.startActivity(activity);
3131
}

src/test/java/io/appium/java_client/android/AndroidAppStringsTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package io.appium.java_client.android;
1818

19-
import static org.junit.Assert.assertNotEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
public class AndroidAppStringsTest extends BaseAndroidTest {
2424

src/test/java/io/appium/java_client/android/AndroidConnectionTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
package io.appium.java_client.android;
1818

19-
import static org.junit.Assert.assertFalse;
20-
import static org.junit.Assert.assertTrue;
19+
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2121

2222
import io.appium.java_client.android.connection.ConnectionState;
2323
import io.appium.java_client.android.connection.ConnectionStateBuilder;
24-
import org.junit.FixMethodOrder;
25-
import org.junit.Test;
26-
import org.junit.runners.MethodSorters;
24+
import org.junit.jupiter.api.MethodOrderer;
25+
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.api.TestMethodOrder;
2727

28-
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
28+
@TestMethodOrder(MethodOrderer.MethodName.class)
2929
public class AndroidConnectionTest extends BaseAndroidTest {
3030

3131
@Test

src/test/java/io/appium/java_client/android/AndroidContextTest.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616

1717
package io.appium.java_client.android;
1818

19-
import static org.junit.Assert.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
2021

2122
import io.appium.java_client.NoSuchContextException;
22-
import org.junit.BeforeClass;
23-
import org.junit.Test;
23+
import org.junit.jupiter.api.BeforeAll;
24+
import org.junit.jupiter.api.Test;
2425

2526
public class AndroidContextTest extends BaseAndroidTest {
2627

27-
@BeforeClass public static void beforeClass2() throws Exception {
28+
@BeforeAll public static void beforeClass2() throws Exception {
2829
Activity activity = new Activity("io.appium.android.apis", ".view.WebView1");
2930
driver.startActivity(activity);
3031
Thread.sleep(20000);
@@ -46,9 +47,12 @@ public class AndroidContextTest extends BaseAndroidTest {
4647
assertEquals(driver.getContext(), "NATIVE_APP");
4748
}
4849

49-
@Test(expected = NoSuchContextException.class) public void testContextError() {
50-
driver.context("Planet of the Ape-ium");
51-
assertEquals("Planet of the Ape-ium", driver.getContext());
50+
@Test public void testContextError() {
51+
assertThrows(NoSuchContextException.class,
52+
() -> {
53+
driver.context("Planet of the Ape-ium");
54+
assertEquals("Planet of the Ape-ium", driver.getContext());
55+
});
5256
}
5357

5458
}

src/test/java/io/appium/java_client/android/AndroidDataMatcherTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import com.google.common.collect.ImmutableList;
2020
import com.google.common.collect.ImmutableMap;
2121
import io.appium.java_client.AppiumBy;
22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323
import org.openqa.selenium.json.Json;
2424
import org.openqa.selenium.support.ui.ExpectedConditions;
2525
import org.openqa.selenium.support.ui.WebDriverWait;
2626

2727
import java.time.Duration;
2828

29-
import static org.junit.Assert.assertNotNull;
29+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3030

3131
public class AndroidDataMatcherTest extends BaseEspressoTest {
3232

src/test/java/io/appium/java_client/android/AndroidDriverTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616

1717
package io.appium.java_client.android;
1818

19+
import static org.hamcrest.MatcherAssert.assertThat;
1920
import static org.hamcrest.Matchers.equalTo;
2021
import static org.hamcrest.Matchers.lessThan;
21-
import static org.junit.Assert.assertEquals;
22-
import static org.junit.Assert.assertFalse;
23-
import static org.junit.Assert.assertNotEquals;
24-
import static org.junit.Assert.assertNotNull;
25-
import static org.junit.Assert.assertThat;
26-
import static org.junit.Assert.assertTrue;
27-
import static org.junit.Assert.fail;
22+
import static org.junit.jupiter.api.Assertions.assertEquals;
23+
import static org.junit.jupiter.api.Assertions.assertFalse;
24+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
25+
import static org.junit.jupiter.api.Assertions.assertNotNull;
26+
import static org.junit.jupiter.api.Assertions.assertTrue;
27+
import static org.junit.jupiter.api.Assertions.fail;
2828

2929
import io.appium.java_client.appmanagement.ApplicationState;
3030
import org.apache.commons.codec.binary.Base64;
3131
import org.apache.commons.io.FileUtils;
3232
import org.hamcrest.Matchers;
33-
import org.junit.Test;
33+
import org.junit.jupiter.api.Test;
3434
import org.openqa.selenium.ScreenOrientation;
3535
import org.openqa.selenium.html5.Location;
3636

src/test/java/io/appium/java_client/android/AndroidElementTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616

1717
package io.appium.java_client.android;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotEquals;
21-
import static org.junit.Assert.assertNotNull;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2222

2323
import io.appium.java_client.AppiumBy;
24-
import org.junit.Before;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
2626
import org.openqa.selenium.By;
2727
import org.openqa.selenium.WebElement;
2828
import org.openqa.selenium.remote.RemoteWebElement;
2929

3030
public class AndroidElementTest extends BaseAndroidTest {
3131

32-
@Before public void setup() {
32+
@BeforeEach public void setup() {
3333
Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
3434
driver.startActivity(activity);
3535
}

src/test/java/io/appium/java_client/android/AndroidFunctionTest.java

+14-11
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
import static java.time.Duration.ofMillis;
44
import static java.time.Duration.ofSeconds;
5+
import static org.hamcrest.MatcherAssert.assertThat;
56
import static org.hamcrest.core.Is.is;
67
import static org.hamcrest.core.StringContains.containsString;
7-
import static org.junit.Assert.assertThat;
8-
import static org.junit.Assert.assertTrue;
8+
import static org.junit.jupiter.api.Assertions.assertThrows;
9+
import static org.junit.jupiter.api.Assertions.assertTrue;
910

1011
import io.appium.java_client.functions.AppiumFunction;
1112
import io.appium.java_client.functions.ExpectedCondition;
12-
import org.junit.Before;
13-
import org.junit.BeforeClass;
14-
import org.junit.Test;
13+
import org.junit.jupiter.api.BeforeAll;
14+
import org.junit.jupiter.api.BeforeEach;
15+
import org.junit.jupiter.api.Test;
1516
import org.openqa.selenium.By;
1617
import org.openqa.selenium.TimeoutException;
1718
import org.openqa.selenium.WebDriver;
@@ -65,15 +66,15 @@ public class AndroidFunctionTest extends BaseAndroidTest {
6566
return null;
6667
};
6768

68-
@BeforeClass
69+
@BeforeAll
6970
public static void startWebViewActivity() {
7071
if (driver != null) {
7172
Activity activity = new Activity("io.appium.android.apis", ".view.WebView1");
7273
driver.startActivity(activity);
7374
}
7475
}
7576

76-
@Before
77+
@BeforeEach
7778
public void setUp() {
7879

7980
driver.context("NATIVE_APP");
@@ -127,17 +128,19 @@ public void complexWaitingTestWithPreCondition() {
127128
assertThat("There should be 3 calls", calls.size(), is(3));
128129
}
129130

130-
@Test(expected = TimeoutException.class)
131+
@Test
131132
public void nullPointerExceptionSafetyTestWithPrecondition() {
132133
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context"))
133134
.withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500));
134-
assertTrue(wait.until(searchingFunction.compose(contextFunction)).size() > 0);
135+
assertThrows(TimeoutException.class,
136+
() -> assertTrue(wait.until(searchingFunction.compose(contextFunction)).size() > 0));
135137
}
136138

137-
@Test(expected = TimeoutException.class)
139+
@Test
138140
public void nullPointerExceptionSafetyTestWithPostConditions() {
139141
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("Fake_context"))
140142
.withTimeout(ofSeconds(30)).pollingEvery(ofMillis(500));
141-
assertTrue(wait.until(contextFunction.andThen(searchingFunction).andThen(filteringFunction)).size() > 0);
143+
assertThrows(TimeoutException.class,
144+
() -> assertTrue(wait.until(contextFunction.andThen(searchingFunction).andThen(filteringFunction)).size() > 0));
142145
}
143146
}

src/test/java/io/appium/java_client/android/AndroidLogcatListenerTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.appium.java_client.android;
22

3-
import static org.junit.Assert.assertTrue;
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
44

55
import org.apache.commons.lang3.time.DurationFormatUtils;
6-
import org.junit.Test;
6+
import org.junit.jupiter.api.Test;
77

88
import java.time.Duration;
99
import java.util.concurrent.Semaphore;
@@ -25,9 +25,9 @@ public void verifyLogcatListenerCanBeAssigned() {
2525
messageSemaphore.acquire();
2626
// This is needed for pushing some internal log messages
2727
driver.runAppInBackground(Duration.ofSeconds(1));
28-
assertTrue(String.format("Didn't receive any log message after %s timeout",
29-
DurationFormatUtils.formatDuration(timeout.toMillis(), "H:mm:ss", true)),
30-
messageSemaphore.tryAcquire(timeout.toMillis(), TimeUnit.MILLISECONDS));
28+
assertTrue(messageSemaphore.tryAcquire(timeout.toMillis(), TimeUnit.MILLISECONDS),
29+
String.format("Didn't receive any log message after %s timeout",
30+
DurationFormatUtils.formatDuration(timeout.toMillis(), "H:mm:ss", true)));
3131
} catch (InterruptedException e) {
3232
throw new IllegalStateException(e);
3333
} finally {

src/test/java/io/appium/java_client/android/AndroidScreenRecordTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import static org.hamcrest.Matchers.is;
66
import static org.hamcrest.Matchers.not;
77

8-
import org.junit.Before;
9-
import org.junit.Test;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
1010
import org.openqa.selenium.WebDriverException;
1111

1212
import java.time.Duration;
1313

1414
public class AndroidScreenRecordTest extends BaseAndroidTest {
1515

16-
@Before
16+
@BeforeEach
1717
public void setUp() {
1818
Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
1919
driver.startActivity(activity);

src/test/java/io/appium/java_client/android/AndroidSearchingTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616

1717
package io.appium.java_client.android;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertNotEquals;
21-
import static org.junit.Assert.assertNotNull;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
2222

2323
import io.appium.java_client.AppiumBy;
24-
import org.junit.Before;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
2626
import org.openqa.selenium.By;
2727
import org.openqa.selenium.WebElement;
2828

2929
public class AndroidSearchingTest extends BaseAndroidTest {
3030

31-
@Before
31+
@BeforeEach
3232
public void setup() {
3333
Activity activity = new Activity("io.appium.android.apis", ".ApiDemos");
3434
driver.startActivity(activity);

src/test/java/io/appium/java_client/android/AndroidTouchTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
import static io.appium.java_client.touch.offset.ElementOption.element;
88
import static io.appium.java_client.touch.offset.PointOption.point;
99
import static java.time.Duration.ofSeconds;
10-
import static org.junit.Assert.assertEquals;
11-
import static org.junit.Assert.assertNotEquals;
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1212

1313
import io.appium.java_client.AppiumBy;
1414
import io.appium.java_client.MultiTouchAction;
1515
import io.appium.java_client.TouchAction;
1616

17-
import org.junit.Before;
18-
import org.junit.Test;
17+
import org.junit.jupiter.api.BeforeEach;
18+
import org.junit.jupiter.api.Test;
1919
import org.openqa.selenium.By;
2020
import org.openqa.selenium.Point;
2121
import org.openqa.selenium.WebElement;
@@ -24,7 +24,7 @@
2424

2525
public class AndroidTouchTest extends BaseAndroidTest {
2626

27-
@Before
27+
@BeforeEach
2828
public void setUp() {
2929
driver.resetApp();
3030
}

src/test/java/io/appium/java_client/android/AndroidViewMatcherTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import com.google.common.collect.ImmutableList;
2020
import com.google.common.collect.ImmutableMap;
2121
import io.appium.java_client.AppiumBy;
22-
import org.junit.Test;
22+
import org.junit.jupiter.api.Test;
2323
import org.openqa.selenium.json.Json;
2424
import org.openqa.selenium.support.ui.ExpectedConditions;
2525
import org.openqa.selenium.support.ui.WebDriverWait;
2626

2727
import java.time.Duration;
2828

29-
import static org.junit.Assert.assertNotNull;
29+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3030

3131
public class AndroidViewMatcherTest extends BaseEspressoTest {
3232

0 commit comments

Comments
 (0)