August 2017
Intermediate to advanced
332 pages
9h 16m
English
We already have the working application. How can we ensure that the logic works as expected? We have tried it once, but in order to know constantly, we need a unit test. In our case, it will be trivial, maybe even unnecessary; however, in real projects, unit tests can save from bugs and system failures.
Let's create a unit test in the file src/test/java/com/leszko/calculator/CalculatorTest.java:
package com.leszko.calculator;import org.junit.Test;import static org.junit.Assert.assertEquals;public class CalculatorTest { private Calculator calculator = new Calculator(); @Test public void testSum() { assertEquals(5, calculator.sum(2, 3)); }}
We can run the test locally using the ./gradlew test command. Then, let's commit ...
Read now
Unlock full access