A simple project to practice writing JUnit 5 tests.
This short guide describes:
In your terminal, navigate to the root directory of this repository, then run the following command to compile the application:
./mvnw clean validate
You should see the following console output:
$ ./mvnw clean validate
[INFO] Scanning for projects...
[INFO]
[INFO] --------------< com.cbfacademy:software-dev-processes >-----------------
[INFO] Building software-dev-processes 1.0.0
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
[More download messages...]
[INFO]
[INFO] --- maven-clean-plugin:3.2.0:clean (default-clean) @ software-dev-processes ---
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/2.0.6/maven-plugin-api-2.0.6.pom
[More download messages...]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.155 s
[INFO] Finished at: 2022-11-03T20:56:09Z
[INFO] ------------------------------------------------------------------------
Examine the class implemented in src/main/java/com/cbfacademy/Calculator.java
.
Create a test class at src/test/java/com/cbfacademy/CalculatorTest.java
.
Write tests to ensure the Calculator can correctly multiply two numbers.
Think of all possible scenarios, and write a test for each of the scenarios you come up with.
To run the tests, use the following command:
./mvnw clean test
To run a specific test method, you can modify the command to include the test class and method. For example, to run a method called testAddition
in the CalculatorTest
class, use the following command:
./mvnw clean test -Dtest=CalculatorTest#testAddition
Once all your tests are passing, commit your changes.
Write tests to ensure the Calculator can divide two numbers.
Think of all possible scenarios, and write a test for each of the scenarios.
One of the scenarios should uncover a flaw in the Calculator implementation.
Run the tests, e.g.:
./mvnw clean test -Dtest=CalculatorTest#testDivision
Once all your tests are passing, commit your changes.
Add more scenarios to cover the calculator's addition and subtraction functionalities.
Once all your tests are passing, commit your changes and push your branch to GitHub.
Enjoy working on your exercise! 😃