|
7 | 7 | import io.qameta.allure.TmsLink; |
8 | 8 | import org.junit.jupiter.api.Test; |
9 | 9 | 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; |
14 | 11 |
|
15 | 12 | public class BodyMassIndexCalculatorTest { |
16 | 13 |
|
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 | | - |
48 | 14 | @Step("Action: Calculate the BMI with a weight of {0} kg and a height of {1} meters") |
49 | 15 | public void printScenario(Double weight, Double height) { |
50 | 16 | } |
51 | 17 |
|
52 | 18 | @TmsLink("TC1234_Formulas") |
53 | 19 | @Feature("Goal: This test case is intended to verify the correct calculation of the Body Mass Index") |
54 | 20 | @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) |
60 | 27 | TestUtil.checkObjectIsNull("BMI", bmiCalculated); |
61 | 28 | else |
62 | | - TestUtil.checkField("BMI", scenario.expectedResult, bmiCalculated); |
| 29 | + TestUtil.checkField("BMI", expectedResult, bmiCalculated); |
63 | 30 | } |
64 | 31 |
|
65 | 32 | //This is an example of a Single Test in the same class with Parameterized Tests |
|
0 commit comments