-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gazelle: Standalone tests depend on their test libraries (#241)
- Loading branch information
1 parent
b04853d
commit 306e4da
Showing
6 changed files
with
97 additions
and
5 deletions.
There are no files selected for viewing
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
36 changes: 36 additions & 0 deletions
36
java/gazelle/testdata/attribute_setting/src/test/com/hastestutil/BUILD.out
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,36 @@ | ||
load("@contrib_rules_jvm//java:defs.bzl", "java_junit5_test", "java_test_suite") | ||
|
||
java_test_suite( | ||
name = "hastestutil", | ||
srcs = [ | ||
"RandomNumberGenerator.java", | ||
"ReliableTest.java", | ||
], | ||
runner = "junit5", | ||
runtime_deps = [ | ||
"@maven//:org_junit_jupiter_junit_jupiter_engine", | ||
"@maven//:org_junit_platform_junit_platform_launcher", | ||
"@maven//:org_junit_platform_junit_platform_reporting", | ||
], | ||
deps = [ | ||
"//src/main/com/example/annotation", | ||
"@maven//:org_junit_jupiter_junit_jupiter_api", | ||
], | ||
) | ||
|
||
java_junit5_test( | ||
name = "RandomTest", | ||
srcs = ["RandomTest.java"], | ||
flaky = True, | ||
test_class = "com.example.hastestutil.RandomTest", | ||
runtime_deps = [ | ||
"@maven//:org_junit_jupiter_junit_jupiter_engine", | ||
"@maven//:org_junit_platform_junit_platform_launcher", | ||
"@maven//:org_junit_platform_junit_platform_reporting", | ||
], | ||
deps = [ | ||
":hastestutil-test-lib", | ||
"//src/main/com/example/annotation", | ||
"@maven//:org_junit_jupiter_junit_jupiter_api", | ||
], | ||
) |
8 changes: 8 additions & 0 deletions
8
java/gazelle/testdata/attribute_setting/src/test/com/hastestutil/RandomNumberGenerator.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,8 @@ | ||
package com.example.hastestutil; | ||
|
||
public class RandomNumberGenerator { | ||
public static int generateNumberLessThanTwo() { | ||
Random random = new Random(); | ||
return random.nextInt(2); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
java/gazelle/testdata/attribute_setting/src/test/com/hastestutil/RandomTest.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,17 @@ | ||
package com.example.hastestutil; | ||
|
||
import com.example.annotation.FlakyTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Random; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@FlakyTest | ||
public class RandomTest { | ||
@Test | ||
public void unreliableTest() { | ||
int r = RandomNumberGenerator.generateNumberLessThanTwo(); | ||
assertEquals(r, 0); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
java/gazelle/testdata/attribute_setting/src/test/com/hastestutil/ReliableTest.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,15 @@ | ||
package com.example.hastestutil; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Random; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class ReliableTest { | ||
@Test | ||
public void reliableTest() { | ||
int r = RandomNumberGenerator.generateNumberLessThanTwo(); | ||
assertTrue(r < 2); | ||
} | ||
} |