https://github.com/yegor256/jping
JUnit5 execution condition that makes sure a connection to a public Internet exists
https://github.com/yegor256/jping
junit junit5 junit5-extension junit5-tests testing unit-testing unit-testing-framework
Last synced: 3 months ago
JSON representation
JUnit5 execution condition that makes sure a connection to a public Internet exists
- Host: GitHub
- URL: https://github.com/yegor256/jping
- Owner: yegor256
- License: mit
- Created: 2023-12-22T13:58:27.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-17T15:37:32.000Z (3 months ago)
- Last Synced: 2025-03-22T21:06:55.875Z (3 months ago)
- Topics: junit, junit5, junit5-extension, junit5-tests, testing, unit-testing, unit-testing-framework
- Language: Java
- Homepage:
- Size: 76.2 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://www.elegantobjects.org)
[](http://www.rultor.com/p/yegor256/jping)
[](https://www.jetbrains.com/idea/)[](https://github.com/yegor256/jping/actions/workflows/mvn.yml)
[](http://www.0pdd.com/p?name=yegor256/jping)
[](https://maven-badges.herokuapp.com/maven-central/com.yegor256/jping)
[](http://www.javadoc.io/doc/com.yegor256/jping)
[](https://codecov.io/gh/yegor256/jping)
[](https://hitsofcode.com/view/github/yegor256/jping)
[](https://github.com/yegor256/jping/blob/master/LICENSE.txt)JUnit5 execution condition that checks whether a connection to public Internet is available.
First, you add this to your `pom.xml`:
```xml
com.yegor256
jping
0.0.3
test```
Then, you use it like this:
```java
import com.yegor256.WeAreOnline;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;@ExtendWith(WeAreOnline.class)
final class MyTest {
@Test
void canDownloadViaHttp() throws Exception {
new URL("https://www.google.com").openStream();
}
}
```Or if need to override default settings:
```java
import com.yegor256.OnlineMeans;
import com.yegor256.WeAreOnline;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;@ExtendWith(WeAreOnline.class)
final class MyTest {
@Test
@OnlineMeans(url = "https://www.amazon.com", connectTimeout = 500, readTimeout = 1500)
void canDownloadViaHttp() throws Exception {
new URL("https://www.amazon.com").openStream();
}
}
```We don't want this unit test to be executed when no Internet connection
is available. The `WeAreOnline` execution condition will prevent JUnit5 from
executing the test when you are offline.## How to Contribute
Fork repository, make changes, send us a [pull request](https://www.yegor256.com/2014/04/15/github-guidelines.html).
We will review your changes and apply them to the `master` branch shortly,
provided they don't violate our quality standards. To avoid frustration,
before sending us your pull request please run full Maven build:```bash
$ mvn clean install -Pqulice
```You will need Maven 3.3+ and Java 8+.