-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand on the ability to include the same test in two suites (#165)
This is to expand the ability of the user to create their own "define_test()" to allow non-default behavior for creating tests within the suite. The goal for this was to add the same test class to two different suites and run them with different configurations. Add documentation about expected use of the define_test() macro run tools/format.sh Co-authored-by: Daniel Wagner-Hall <[email protected]>
- Loading branch information
1 parent
a9509d8
commit dda039c
Showing
5 changed files
with
120 additions
and
13 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/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/suite_tags/BUILD.bazel
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("@rules_jvm_external//:defs.bzl", "artifact") | ||
load("//java:defs.bzl", "junit5_deps") | ||
load(":java_test_suite.bzl", "java_test_suite") | ||
|
||
java_test_suite( | ||
name = "Junit5TagsTest_only_never", | ||
size = "small", | ||
srcs = ["Junit5TagsTest.java"], | ||
exclude_tags = ["Never"], | ||
deps = [ | ||
artifact("org.junit.jupiter:junit-jupiter-api", "contrib_rules_jvm_tests"), | ||
] + junit5_deps("contrib_rules_jvm_tests"), | ||
) | ||
|
||
java_test_suite( | ||
name = "Junit5TagsTest_no_sometimes", | ||
size = "small", | ||
srcs = ["Junit5TagsTest.java"], | ||
exclude_tags = [ | ||
"Never", | ||
"Sometimes", | ||
], | ||
deps = [ | ||
artifact("org.junit.jupiter:junit-jupiter-api", "contrib_rules_jvm_tests"), | ||
] + junit5_deps("contrib_rules_jvm_tests"), | ||
) | ||
|
||
java_test_suite( | ||
name = "Junit5TagsTest_only_always", | ||
size = "small", | ||
srcs = ["Junit5TagsTest.java"], | ||
include_tags = ["Always"], | ||
deps = [ | ||
artifact("org.junit.jupiter:junit-jupiter-api", "contrib_rules_jvm_tests"), | ||
] + junit5_deps("contrib_rules_jvm_tests"), | ||
) |
34 changes: 34 additions & 0 deletions
34
java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/suite_tags/Junit5TagsTest.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,34 @@ | ||
package com.github.bazel_contrib.contrib_rules_jvm.junit5.suite_tags; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class Junit5TagsTest { | ||
|
||
@Test | ||
@Tag("Always") | ||
public void alwaysRun() { | ||
assertTrue(true); | ||
} | ||
|
||
@Test | ||
@Tag("Never") | ||
public void neverRun() { | ||
assertTrue(false); | ||
} | ||
|
||
@Test | ||
@Tag("Sometimes") | ||
public void runSometimes() { | ||
// exclude shouldn't run | ||
if (System.getProperty("JUNIT5_EXCLUDE_TAGS", "").contains("Sometimes")) { | ||
assertTrue(false, "Should have skippend this test"); | ||
} else if (System.getProperty("JUNIT5_INCLUDE_TAGS", "").contains("Sometimes")) { | ||
assertTrue(true, "Positive ask to run this test"); | ||
} else { | ||
assertTrue(true, "Not specifically filtered, but run anyway"); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/suite_tags/java_test_suite.bzl
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,35 @@ | ||
load("//java:defs.bzl", "java_junit5_test", "java_library", test_suite = "create_jvm_test_suite") | ||
|
||
def _define_junit5_test(name, **kwargs): | ||
duplicate_test_name = kwargs.pop("duplicate_test_name", None) | ||
|
||
test_name = "%s-%s" % (duplicate_test_name, name) if duplicate_test_name else name | ||
java_junit5_test( | ||
name = test_name, | ||
**kwargs | ||
) | ||
|
||
return test_name | ||
|
||
def _define_library(name, **kwargs): | ||
java_library( | ||
name = name, | ||
**kwargs | ||
) | ||
|
||
def java_test_suite( | ||
name, | ||
runner = "junit5", | ||
test_suffixes = ["Test.java"], | ||
package = None, | ||
**kwargs): | ||
test_suite( | ||
name, | ||
test_suffixes = test_suffixes, | ||
package = package, | ||
define_test = _define_junit5_test, | ||
define_library = _define_library, | ||
runner = runner, | ||
duplicate_test_name = name, | ||
**kwargs | ||
) |