-
Notifications
You must be signed in to change notification settings - Fork 71
/
RetryingTestExtensionDemo.java
78 lines (65 loc) · 1.99 KB
/
RetryingTestExtensionDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright 2016-2023 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* http://www.eclipse.org/legal/epl-v20.html
*/
package org.junitpioneer.jupiter;
public class RetryingTestExtensionDemo {
// tag::retrying_failsNever[]
@RetryingTest(3)
void failsNever() {
// passing test code
}
// end::retrying_failsNever[]
// tag::retrying_fails_on_first_but_passes_on_second[]
@RetryingTest(3)
void failsOnlyOnFirstInvocation() {
// test code that fails on first execution
// but passes on the second
}
// end::retrying_fails_on_first_but_passes_on_second[]
// tag::retrying_fails_always[]
@RetryingTest(3)
void failsAlways() {
// test code that always fails
}
// end::retrying_fails_always[]
// tag::retrying_aborted[]
@RetryingTest(3)
void aborted() {
// test code that is aborted,
// e.g. because of an `Assumption`.
}
// end::retrying_aborted[]
// tag::retrying_configure_numbers_of_success[]
@RetryingTest(maxAttempts = 4, minSuccess = 2)
void requiresTwoSuccesses() {
// test code that must complete successfully twice
}
// end::retrying_configure_numbers_of_success[]
// tag::suspending_between_each_retry[]
@RetryingTest(maxAttempts = 3, suspendForMs = 100)
void suspendsBetweenRetries() {
// test code that will suspend/wait for 100 ms between retries
}
// end::suspending_between_each_retry[]
class TheseTestsWillFailIntentionally {
// tag::retrying_configure_exception_for_retry[]
private int EXECUTION_COUNT;
@RetryingTest(value = 3, onExceptions = IllegalArgumentException.class)
void failsFirstWithExpectedThenWithUnexpectedException() {
EXECUTION_COUNT++;
if (EXECUTION_COUNT == 1) {
throw new IllegalArgumentException();
}
if (EXECUTION_COUNT == 2) {
throw new NullPointerException();
}
}
// end::retrying_configure_exception_for_retry[]
}
}