-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement JUnit5 support and parameterize tests (#4473)
* Implement JUnit5 support and parameterize tests * feat: Capture main class for java tests * feat: Use main class for fast tests if there is any --------- Co-authored-by: Borja Lorente <[email protected]> Co-authored-by: Andrzej Głuszak <[email protected]>
- Loading branch information
1 parent
c29c248
commit 842a0ae
Showing
30 changed files
with
2,741 additions
and
540 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
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
Empty file.
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
3 changes: 2 additions & 1 deletion
3
...g_lib/tests/com/example/GreetingTest.java → ...ests/com/example/junit4/GreetingTest.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
30 changes: 30 additions & 0 deletions
30
...va/greetings_project/greeting_lib/tests/com/example/junit4/ParameterizedGreetingTest.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,30 @@ | ||
package com.example.junit4; | ||
|
||
import com.example.Greeting; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(Parameterized.class) | ||
public class ParameterizedGreetingTest { | ||
@Parameterized.Parameter | ||
public String name; | ||
|
||
@Parameterized.Parameters(name = "Test name {0}") | ||
public static String[] names() { | ||
return new String[]{"Henry", "Roberta"}; | ||
} | ||
|
||
@Test | ||
public void testGreetOneName() { | ||
List<String> got = Greeting.getGreetings("greetings", Collections.singletonList(name)); | ||
assertEquals(1, got.size()); | ||
String expected = "greetings " + name + "!"; | ||
assertEquals(expected, got.get(0)); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
examples/java/greetings_project/greeting_lib/tests/com/example/junit5/GreetingTest.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.example.junit5; | ||
|
||
import com.example.Greeting; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class GreetingTest { | ||
@Test | ||
public void testGreetNoNames() { | ||
List<String> got = Greeting.getGreetings("greetings", Collections.emptyList()); | ||
assertEquals(0, got.size()); | ||
} | ||
|
||
@Test | ||
public void testGreetOneName() { | ||
List<String> got = Greeting.getGreetings("greetings", Collections.singletonList("name")); | ||
assertEquals(1, got.size()); | ||
assertEquals("greetings name!", got.get(0)); | ||
} | ||
|
||
@Test | ||
public void testGreetMultipleNames() { | ||
List<String> got = Greeting.getGreetings("greetings", Arrays.asList("name1", "name2", "name3")); | ||
assertEquals(3, got.size()); | ||
assertEquals("greetings name1!", got.get(0)); | ||
assertEquals("greetings name2!", got.get(1)); | ||
assertEquals("greetings name3!", got.get(2)); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...va/greetings_project/greeting_lib/tests/com/example/junit5/ParameterizedGreetingTest.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,23 @@ | ||
package com.example.junit5; | ||
|
||
import com.example.Greeting; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ParameterizedGreetingTest { | ||
@ParameterizedTest | ||
@ValueSource(strings = { "Henry", "Roberta" }) | ||
public void testGreetOneName(String name) { | ||
List<String> got = Greeting.getGreetings("greetings", Collections.singletonList(name)); | ||
assertEquals(1, got.size()); | ||
String expected = "greetings " + name + "!"; | ||
assertEquals(expected, got.get(0)); | ||
} | ||
} |
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,60 @@ | ||
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external") | ||
|
||
JUNIT_JUPITER_VERSION = "5.9.2" | ||
|
||
JUNIT_PLATFORM_VERSION = "1.9.2" | ||
|
||
_JUNIT5_DEPS_TO_FETCH = [ | ||
{ | ||
"name": "junit_platform_launcher", | ||
"coords": "org.junit.platform:junit-platform-launcher:%s" % JUNIT_PLATFORM_VERSION, | ||
"artifact_sha256": "eef139eb09c98e9cdd358b6ce4c6cdd59b30c6a88096e369c33ba96e67edf0e4", | ||
}, | ||
{ | ||
"name": "junit_platform_reporting", | ||
"coords": "org.junit.platform:junit-platform-reporting:%s" % JUNIT_PLATFORM_VERSION, | ||
"artifact_sha256": "d6788db1c941c1247e07d8104f57c3f06175cadfd43060a792493fe9195671db", | ||
}, | ||
{ | ||
"name": "junit_platform_commons", | ||
"coords": "org.junit.platform:junit-platform-commons:%s" % JUNIT_PLATFORM_VERSION, | ||
"artifact_sha256": "624a3d745ef1d28e955a6a67af8edba0fdfc5c9bad680a73f67a70bb950a683d", | ||
}, | ||
{ | ||
"name": "junit_platform_engine", | ||
"coords": "org.junit.platform:junit-platform-engine:%s" % JUNIT_PLATFORM_VERSION, | ||
"artifact_sha256": "25f23dc535a091e9dc80c008faf29dcb92be902e6911f77a736fbaf019908367", | ||
}, | ||
{ | ||
"name": "junit_jupiter_api", | ||
"coords": "org.junit.jupiter:junit-jupiter-api:%s" % JUNIT_JUPITER_VERSION, | ||
"artifact_sha256": "f767a170f97127b0ad3582bf3358eabbbbe981d9f96411853e629d9276926fd5", | ||
}, | ||
{ | ||
"name": "junit_jupiter_params", | ||
"coords": "org.junit.jupiter:junit-jupiter-params:%s" % JUNIT_JUPITER_VERSION, | ||
"artifact_sha256": "bde91900a5ce5d6663bb44bc708494b35daefcd73e1bb7afa61a4affe38ea97d", | ||
}, | ||
{ | ||
"name": "junit_jupiter_engine", | ||
"coords": "org.junit.jupiter:junit-jupiter-engine:%s" % JUNIT_JUPITER_VERSION, | ||
"artifact_sha256": "74cfc49388f760413ff348ca2c9ab39527484b57deecd157f2275a5f8a5fe971", | ||
}, | ||
{ | ||
"name": "opentest4j", | ||
"coords": "org.opentest4j:opentest4j:1.2.0", | ||
"artifact_sha256": "58812de60898d976fb81ef3b62da05c6604c18fd4a249f5044282479fc286af2", | ||
}, | ||
] | ||
|
||
JUNIT5_DEPS = ["@{name}//jar".format(name = dep["name"]) for dep in _JUNIT5_DEPS_TO_FETCH] | ||
|
||
def instantiate_junit5_deps(): | ||
for dep in _JUNIT5_DEPS_TO_FETCH: | ||
jvm_maven_import_external( | ||
name = dep["name"], | ||
artifact = dep["coords"], | ||
artifact_sha256 = dep["artifact_sha256"], | ||
licenses = ["notice"], # Common Public License 1.0 | ||
server_urls = ["https://repo1.maven.org/maven2"], | ||
) |
Oops, something went wrong.