-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for junit 5 parameterized tests (#120)
- Loading branch information
Showing
3 changed files
with
158 additions
and
10 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...mples/src/test/java/com/github/noconnor/junitperf/examples/ExampleParameterizedTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.github.noconnor.junitperf.examples; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.net.Socket; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import com.github.noconnor.junitperf.JUnitPerfInterceptor; | ||
import com.github.noconnor.junitperf.JUnitPerfTest; | ||
import com.github.noconnor.junitperf.TestContextSupplier; | ||
import com.github.noconnor.junitperf.data.TestContext; | ||
|
||
@ExtendWith(JUnitPerfInterceptor.class) | ||
public class ExampleParameterizedTests { | ||
|
||
static List<String> hostnames() { | ||
return Arrays.asList("www.google.com", "www.example.com"); | ||
} | ||
|
||
@MethodSource("hostnames") | ||
@ParameterizedTest(name = "test1(hostname = {0})") | ||
@JUnitPerfTest(durationMs = 3_000, maxExecutionsPerSecond = 1) | ||
public void test1(String hostname) throws IOException { | ||
try (Socket socket = new Socket()) { | ||
socket.connect(new InetSocketAddress(hostname, 80), 1000); | ||
} | ||
} | ||
|
||
@MethodSource("hostnames") | ||
@ParameterizedTest(name = "test2(hostname = {0})") | ||
@JUnitPerfTest(durationMs = 3_000, maxExecutionsPerSecond = 1) | ||
public void test2(String hostname, TestContextSupplier supplier) { | ||
TestContext context = supplier.startMeasurement(); | ||
try (Socket socket = new Socket()) { | ||
socket.connect(new InetSocketAddress(hostname, 80), 1000); | ||
context.success(); | ||
} catch (IOException e) { | ||
context.fail(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters