Test-Driven Development – How to write a test before none of implementation code exists

Create EnrollingServiceTest class in src/test/java in the same package as EnrollingService

class EnrollingServiceTest {
    private EnrollingService enrollingService;

    @Before 
    public void init() {
           enrollingService = new EnrollingService();
    }

    @Test
    public void testEnroll() {
           boolean result = enrollingService.enroll(1l, 1l);
           assertTrue(result);
    ...

IDE (I am assuming you are using IDE) shows errors – EnrollingService does not exists .

Point cursor on EnrollService – IDE will offer to create a class – let it create in src/main/java

Now IDE says that enroll(long, long) method is missing – let IDE create it for you.

Now IDE shows no errors. Run the test – it fails. Go to enroll and start implementing the logic

And so on…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)