Skip to content

Commit

Permalink
Add integration test case to separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
indikaeranga committed Feb 27, 2024
1 parent 1d438df commit 5374c08
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 45 deletions.
77 changes: 50 additions & 27 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions src/test/java/ITCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,38 @@
import org.example.Main;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvFileSource;

import static org.junit.Assert.*;

public class ITCalculator {

private Main main;

@BeforeEach
void setup() {
main = new Main();
}
@ParameterizedTest
@CsvFileSource(resources = "/TestData_AdditionAndMultiplication.csv")
public void testAdditionAndMultiplication(int mulParam1, int mulParam2, int addParam, int expectedResult) {

// Perform the multiplication and add the third parameter to the result of multiplication
int totalResult = main.Add(main.Multiply(mulParam1, mulParam2), addParam);
// Assert that the total result matches the expected result
Assertions.assertEquals(expectedResult, totalResult);
}
@ParameterizedTest
@CsvFileSource(resources = "/TestData_DivisionAndSubtraction.csv")
public void testDivisionAndSubtraction(int subParam1, int subParam2, int divParam, int expectedResult) {
// Perform the subtraction
int subResult = main.Substract(subParam1, subParam2);
// Perform the division with the result of subtraction
int divResult = main.Divide(subResult, divParam);
// Assert that the result of division matches the expected result
Assertions.assertEquals(expectedResult, divResult);
}
}
18 changes: 0 additions & 18 deletions src/test/java/TestCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,7 @@ public void testRoundValue(float input, int expected) {
int roundedResult = main.rountvalue(input);
Assertions.assertEquals(expected, roundedResult);
}
@ParameterizedTest
@CsvFileSource(resources = "/TestData_AdditionAndMultiplication.csv")
public void testAdditionAndMultiplication(int mulParam1, int mulParam2, int addParam, int expectedResult) {

// Perform the multiplication and add the third parameter to the result of multiplication
int totalResult = main.Add(main.Multiply(mulParam1, mulParam2), addParam);
// Assert that the total result matches the expected result
Assertions.assertEquals(expectedResult, totalResult);
}
@ParameterizedTest
@CsvFileSource(resources = "/TestData_DivisionAndSubtraction.csv")
public void testDivisionAndSubtraction(int subParam1, int subParam2, int divParam, int expectedResult) {
// Perform the subtraction
int subResult = main.Substract(subParam1, subParam2);
// Perform the division with the result of subtraction
int divResult = main.Divide(subResult, divParam);
// Assert that the result of division matches the expected result
Assertions.assertEquals(expectedResult, divResult);
}


}

0 comments on commit 5374c08

Please sign in to comment.