Skip to content

Commit 9cadd97

Browse files
olgapuigjazzinjars
authored andcommitted
JUnit5 - Use CsvFileSource instead of MethodSource (#42)
1 parent 613a213 commit 9cadd97

File tree

2 files changed

+20
-41
lines changed

2 files changed

+20
-41
lines changed

src/test/java/com/systelab/seed/patient/control/BodyMassIndexCalculatorTest.java

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,26 @@
77
import io.qameta.allure.TmsLink;
88
import org.junit.jupiter.api.Test;
99
import org.junit.jupiter.params.ParameterizedTest;
10-
import org.junit.jupiter.params.provider.MethodSource;
11-
12-
import java.util.Arrays;
13-
import java.util.List;
10+
import org.junit.jupiter.params.provider.CsvFileSource;
1411

1512
public class BodyMassIndexCalculatorTest {
1613

17-
static class Scenario {
18-
public Double weight;
19-
public Double height;
20-
public Double expectedResult;
21-
22-
public Scenario(Double weight, Double height, Double expectedResult) {
23-
this.weight = weight;
24-
this.height = height;
25-
this.expectedResult = expectedResult;
26-
}
27-
}
28-
29-
static List<Scenario> scenarios() {
30-
// @formatter:off
31-
return Arrays.asList(
32-
new Scenario(0.0, 0.0, null),
33-
new Scenario(-1.0, 0.0, null),
34-
new Scenario(-1.0, 1.0, null),
35-
new Scenario(1.0, -1.0, null),
36-
new Scenario(1.0, 0.0, null),
37-
new Scenario(5.0, 0.1, null),
38-
new Scenario(30.0, 0.5, 120.0),
39-
new Scenario(45.0, 1.0, 45.0),
40-
new Scenario(65.0, 1.40, 33.2),
41-
new Scenario(75.0, 1.8, 23.1),
42-
new Scenario(95.0, 1.8, 29.3),
43-
new Scenario(78.5, 1.805, 24.1)
44-
);
45-
// @formatter:on
46-
}
47-
4814
@Step("Action: Calculate the BMI with a weight of {0} kg and a height of {1} meters")
4915
public void printScenario(Double weight, Double height) {
5016
}
5117

5218
@TmsLink("TC1234_Formulas")
5319
@Feature("Goal: This test case is intended to verify the correct calculation of the Body Mass Index")
5420
@ParameterizedTest
55-
@MethodSource("scenarios")
56-
public void checkBMICalculationForCorrectValuesTest(Scenario scenario) {
57-
printScenario(scenario.weight, scenario.height);
58-
Double bmiCalculated = BodyMassIndexCalculator.getBMI(scenario.weight, scenario.height);
59-
if (scenario.expectedResult == null)
21+
@CsvFileSource(resources = "/bodyMassIndexCalculator.csv")
22+
public void checkBMICalculationForCorrectValuesTest(Double weight, Double height, String expectedResultStr) {
23+
Double expectedResult = expectedResultStr.equals("null") ? null : Double.parseDouble(expectedResultStr);
24+
printScenario(weight, height);
25+
Double bmiCalculated = BodyMassIndexCalculator.getBMI(weight, height);
26+
if (expectedResult == null)
6027
TestUtil.checkObjectIsNull("BMI", bmiCalculated);
6128
else
62-
TestUtil.checkField("BMI", scenario.expectedResult, bmiCalculated);
29+
TestUtil.checkField("BMI", expectedResult, bmiCalculated);
6330
}
6431

6532
//This is an example of a Single Test in the same class with Parameterized Tests
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
0.0, 0.0, null
2+
-1.0, 0.0, null
3+
-1.0, 1.0, null
4+
1.0, -1.0, null
5+
1.0, 0.0, null
6+
5.0, 0.1, null
7+
30.0, 0.5, 120.0
8+
45.0, 1.0, 45.0
9+
65.0, 1.40, 33.2
10+
75.0, 1.8, 23.1
11+
95.0, 1.8, 29.3
12+
78.5, 1.805, 24.1

0 commit comments

Comments
 (0)