samedi 23 janvier 2016

Using random value in a JUnit test class

Is it a good pratice to use random value to create a test object with JUnit ? Like this :

public class MonomialTest {

    private static final Random RANDOM = new Random();

    private Monomial monomial;
    private float coefficient;
    private int exponent;

    @Before
    public void setUp() throws Exception {
        coefficient = RANDOM.nextFloat();
        exponent = RANDOM.nextInt();
        monomial = new Monomial(coefficient, exponent);
    }

    @Test
    ...
    ...
    ...

}

Or should I use fixed values ?




Aucun commentaire:

Enregistrer un commentaire