samedi 10 janvier 2015

Why should you avoid conditional logic in unit tests and how?

Imagine having the following classes:



public class Product {
private String name;
private double price;

// Constructors, getters and setters
}

public class Products {
private List<Product> products;

// CRUD methods

public double getTotalPrice() {
// calculates the price of all products
}
}


I have read that conditional logic(if's and loops) should be avoided in unit tests, but didn't understand exactly why and more importantly how. How can I efficiently test the scenario where I add some products in Products with different prices and then verify the result of getTotalPrice() without using loops?


Aucun commentaire:

Enregistrer un commentaire