Framework to test in the unit layer.
To practice this I built a class to calculate the Body Mass Index (BMI) and a test class to test the methods of retrieving a result based on a size and a weight of a person.
I used a data-driven approach to run the test class using a csv file with different data and also a structure of Suites so I can run tests in an optimized way. There are 3 Suites of tests basically. One with Positive scenarios and another with Smoke tests with the most important ones. A third Suite runs all test classes as long as I parameterize them. It is also possible to run the tests with CLI and the results we can view with Allure Report.
Tools:
Dependências:
./project
├─ src/
├─ main
└─ java/
└─ bmi/
└─ BMI
└─ categories/
├─ Positives
├─ Smoke
└─ test/
└─ java/
└─ bmi/
├─ CalculateBMI_CSVTest
├─ CategorizedTestsTest
├─ Suite_AllTestsTest
├─ Suite_PositiveCatergoriesTest
└─ Suite_SmokeCatergoriesTest
└─ resources/
└─ data.csv
- src: main dir
- main: dir with the base code
- java: default dir when the project is created
- bmi: package with base code classes
- BMI: class with the Body Mass Index logic
- categories: package with interfaces to support the Suite approach
- test: package with test classes
- java: default dir when the project is created
- bmi: package with test classes
- CalculateBMI_CSVTest: test class with the data-driven approach that consumes the csv file
- CategorizedTestsTest: test class with categorized methods that will support Suite classes based on categories
- Suite_AllTestsTest: test class to parameterize all classes you want to run easily with one click
- Suite_PositiveCatergoriesTest: test class to parameterize all methods categorized as Positives
- Suite_SmokeCatergoriesTest: test class to parameterize all methods categorized as Smoke
- resources: dir with csv file
Run all test classes through command line:
mvn surfire:test
As soon as the tests are executed, a folder will be created inside the "target" directory, called "surefire-reports".
Open the Allure test report via command line:
allure serve /PATH
*
*The path must be changed to the path of the "surefire-reports" folder created in the previous step.