Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In this tutorial we will dive into JUnit5 framework even more basing on very simple Calculator project that will grow with us during tutorial.


...

Info

The tutorial repository can be found here:

https://gitlab.eufus.eu/bpogodzinski/ach-tutorials/-/tree/TDD-java/TDD-java/Calculator

...

Our Calculator.java  look like this:

As you can see it has only divide() method, that checks if b is equal to 0. If it is, it throws an exception.

Code Block
public class Calculator {

    static Double divide(Double a, Double b) {
        if (b != 0) {
            return a / b;
        }
        else{
            throw new ArithmeticException("Division by 0 is impossible!");
        }
    }

    public static void main(String[] args) {
        System.out.printf(Calculator.divide(8.0,2.0).toString());
    }

}

...



So let's write first simple test:

...