Skip to main content

Posts

Showing posts from July, 2016

Unit Tests - Why are they so important?

Why do we need Unit Testing? There are two important reason : To test different scenarios and making sure the logic we have just written works as expected In case a developer is changing the logic in future, they notice whether they have broken the existing logic or not What Should Be Tested? Different scenarios: E.g. each if-else statement can be taken as a separate scenario Data that we expect to be changed within a method Possible exceptions that may be thrown What Does Not Need to Be Tested? Mocked data that we created as input data Any result from a third party API. E.g: Hibernate, Spring etc. Results from classes that are already tested in their own unit tests. Example public Employer save(Employer employer) { if (employer.getActivateFlag() != null ) { if (employer.getActivateFlag()) { employer.setStatus(Status.Active); } else { employer.setStatus(Status.Inactive); }