Abort tests if URL is unreachable
See original GitHub issueImagine having a suite of integration-y tests that use some service that’s fickle and may be down occasionally and that you’re ok with not running the tests if it isn’t reachable.
Enter DisabledIfUnreachable
extension!
@DisabledIfUnreachable(url = "some.url", timeoutMillis = 5_000)
class FickleServiceRelatedTests {
void testA() {
// something with the service
}
@DisabledIfUnreachable(url = "some.other.url", timeoutMillis = 5_000)
void testB() {
// something else with the service
}
}
Test A is disabled if some.url
isn’t reachable (i.e. times out in 5 seconds or returns a status code outside of 200-399). Same for B but it is also disabled if some.other.url
isn’t reachable.
I’ve started playing with this idea a few years ago and have just put the code I wrote into this gist (which should be seen as experimental and not up to our quality standards; also it uses EnabledIf
wording, but I don’t think that’s a good idea).
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How to Check if a Website is Up or Down [5 Ways] - Geekflare
Simply enter the URL or name of the website you would like to test and click “Check”. Compared to other simple ping sites,...
Read more >Set Up and Tear Down State in Your Tests - Apple Developer
When you run a test case, XCTest calls the XCTestCase setUp() class method first. Use this method to set up state common to...
Read more >How can I simulate a 'down' website? - Stack Overflow
However, I cannot seem to figure out how to simulate a test if a website is 'down' or not. If I try an...
Read more >Is This Website Down? How to Check if Your Site is Working ...
Here are the steps to check your website online status using this test tool: Visit Site24x7, and you will instantly see a field...
Read more >unittest — Unit testing framework — Python 3.11.1 ...
(If you are already familiar with the basic concepts of testing, you might want to skip to the list of ... Stop the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hm, I’m not a 100% sure that an annotation is the proper place for what is essentially an assumption.
We should consider providing this functionality in the form of a utility class (e.g.
PioneerAssumptions
) with anassumeUrlIsReachable(String url, int timeoutMillis)
I’m totally with you: This cleary is an assumption.