blob: 1e0ec244c81b3793a5350f60d2203ef66b5af6a2 (
plain)
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
|
package junitparams.naming;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.Request;
import org.junit.runner.RunWith;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import static org.assertj.core.api.Assertions.*;
@RunWith(JUnitParamsRunner.class)
public class NamingStrategyIsUsedByRunnerTest {
@AfterClass
public static void checkTestCaseNames() {
Description rootDescription = getTestClassDescription();
String className = "(" + NamingStrategyIsUsedByRunnerTest.class.getCanonicalName() + ")";
Description sampleMethodDescription = getChildDescriptionByName(rootDescription, "sampleMethod");
assertThat(sampleMethodDescription.getChildren()).extracting("displayName").containsExactly(
"[0] Well formed name of sampleMethod with param1" + className,
"[1] Well formed name of sampleMethod with param2" + className);
}
@Test
@Parameters({"param1", "param2"})
@TestCaseName("[{index}] Well formed name of {method} with {params}")
public void sampleMethod(String parameter) {
}
private static Description getTestClassDescription() {
return Request.aClass(NamingStrategyIsUsedByRunnerTest.class).getRunner().getDescription();
}
private static Description getChildDescriptionByName(Description parent, String expectedName) {
for (Description childDescription : parent.getChildren()) {
if (expectedName.equals(childDescription.getDisplayName())) {
return childDescription;
}
}
return null;
}
}
|