Skip to content

Commit adf9d7d

Browse files
committed
Add reason field to MockOnly
This enforces developers to document why a test is skipped
1 parent ea52030 commit adf9d7d

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/MockOnly.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.lang.annotation.RetentionPolicy;
77
import java.lang.annotation.Target;
88

9+
import javax.annotation.Nonnull;
10+
911
/**
1012
* Marker annotation to skip test if it not run with mocks.
1113
*
@@ -15,4 +17,9 @@
1517
@Target({ElementType.METHOD, ElementType.TYPE})
1618
@Inherited
1719
public @interface MockOnly {
20+
21+
/**
22+
* Explanation why this test shold only be run with mocks and not against real websites
23+
*/
24+
@Nonnull String reason();
1825
}

extractor/src/test/java/org/schabi/newpipe/MockOnlyRule.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ public Statement apply(@Nonnull Statement base, @Nonnull Description description
3333
return new Statement() {
3434
@Override
3535
public void evaluate() throws Throwable {
36-
final boolean hasAnnotation = description.getAnnotation(MockOnly.class) == null;
37-
final boolean isMockDownloader = downloader == null ||
38-
!downloader.equalsIgnoreCase(DownloaderType.REAL.toString());
39-
Assume.assumeTrue(
40-
"The test is not reliable against a website and thus skipped",
41-
hasAnnotation && isMockDownloader
42-
);
36+
final MockOnly annotation = description.getAnnotation(MockOnly.class);
37+
if (annotation != null) {
38+
final boolean isMockDownloader = downloader == null ||
39+
!downloader.equalsIgnoreCase(DownloaderType.REAL.toString());
40+
41+
Assume.assumeTrue("The test is not reliable against real website. Reason: "
42+
+ annotation.reason(), isMockDownloader);
43+
}
44+
4345

4446
base.evaluate();
4547
}

0 commit comments

Comments
 (0)