mardi 19 avril 2016

Is it a good idea in a test class to use constants of the subject class in assertions?

Is it considered bad practice to use a constant of the subject class in assertions?

@Test
public void testSubjectMethod() throws Exception {
    Subject subject = new Subject()

    String result = subject.subjectMethod();

    Assert.assertEquals(result, Subject.VALUE);
}

Or should I maintain a separate value in the test class and use that?

private static final String SUBJECT_VALUE = "SUBJECT_VALUE";

@Test
public void testSubjectMethod() throws Exception {
    Subject subject = new Subject()

    String result = subject.subjectMethod();

    Assert.assertEquals(result, SUBJECT_VALUE);
}

Aucun commentaire:

Enregistrer un commentaire