0

I am new at JUnit. I try to write unit test of a simple service class which is "ProductService". Here is my test codes for "ProductService"

public interface TestProductService {

    void shouldCreateProduct() throws EntityIsAlreadyCreatedException;
    void shouldDeleteProductById() throws EntityNotfoundException;
    void shouldUpdateProduct();
    void shouldFindProductById() throws EntityNotfoundException;
    void shouldFindAllProducts() throws EntityNotfoundException;
    void shouldThrowErrorWhenFindAllProductsWhichAreNotInDB();
    void shouldThrowErrorWhenFindProductWhichAreNotInDB() throws EntityNotfoundException;
    void shouldThrowErrorWhenDeleteProductWhichIsNotInDB() throws EntityNotfoundException;
    void shouldThrowErrorWhenCreateProductWhichIsAlreadyInDB() throws EntityIsAlreadyCreatedException;

 
}

As you see, there are some functions which can throw error. In addition, other functions test simple "CRUD" operations. Should I seperate the functions which can throw error to another interface ? If I seperate them, can I provide to interface segregation ? Thanks your help.

EMRE BİNNAZ
  • 43
  • 1
  • 8

1 Answers1

1

Interface segregation should be done based on the functionality. If you consider it as a principle "clients implementing the interface should not be forced to depend upon interfaces that they do not use". That means it was good to have separate interface for each functionality rather pushing the client to implement unrelated functionalities. But in your case I'm curious why would you have a interface for the Tests, what benefit it would provide to yours... Even if you do, it does not has to be a separate interface for error throwing scenarios. Rather good test design is have a one to one mapping for class implementation which you are creating the tests for

ProductService >> TestProductService or ProductServiceTest 
user2739602
  • 301
  • 5
  • 4