mercredi 30 décembre 2015

Unit tests for mapping methods that call getters and setters

Suppose I want to create a unit test for a method like this:

public Car map(CarReq request) {

    Car car = new Car();
    car.setPrice(carReq.getPrice());
    car.setColour(carReq.getColour());
    car.setType(carReq.getType());

    // Other 20 lines like these

    return car;
}

I can mock carRequest and tell each method what should return. But that's like not testing anything, as all the method does is getting values from carReq.

I can create a testing carReq object (without mocking) and check that the same values are copied into the output Car object. But that's a lot of work, right?

Isn't there a more intelligent way?

Aucun commentaire:

Enregistrer un commentaire