Unit tests
Standard unit tests are created and executed same as for any other Java classes. There is nothing special. So if you for example have service:
package com.example.service.interfaces;
public interface CalculatorService {
Integer add(Integer a, Integer b);
}
And its implementation:
package com.example.service.impl;
import com.example.service.interfaces.CalculatorService;
import org.springframework.stereotype.Service;
@Service(value = "multiplierService")
public class CalculatorServiceImpl implements CalculatorService {
@Override
public Integer add(Integer a, Integer b) {
return a + b;
}
}
If you are using for example JUnit just create test class:
import com.example.service.interfaces.CalculatorService;
import com.example.service.impl.CalculatorServiceImpl;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class CalculatorServiceTest {
@Test
public void testAddMethod() {
CalculatorService calculator = new CalculatorServiceImpl();
Integer sum = calculator.add(2, 2);
assertEquals(4, sum);
}
}
Now if you are using Maven for your project just run command mvn test
and see you result.