-2
public enum DivisionConstant {
    consumer(1), office(2), production_printing(3);
}

For this enum I wrote a junit test as:

@Test
public void testDivisionConstantFromInt()
{
    DivisionConstant d  = DivisionConstant.fromInt(1);
    assertTrue((d.toName().compareToIgnoreCase("consumer") ==  0));
}

When I execute this it shows only true or false. But I want to know if the test case won't work I want to the reason for the failure of the test

mmmmmm
  • 32,227
  • 27
  • 88
  • 117
Harsha
  • 3
  • 1
  • 1
  • 2
  • 1
    Use something like the hamcrest assertions: `assertThat(d.toName, is("consumer"))`, to get more expressive error messages. – Carl Manaster Dec 30 '14 at 18:35
  • possible duplicate of [junit assertEquals ignore case](http://stackoverflow.com/questions/17652051/junit-assertequals-ignore-case) – Joe Jan 01 '15 at 06:38

2 Answers2

4

This you need to supply yourself

assertTrue("Name was not lexically identical to \"consumer\"", 
       d.toName().compareToIgnoreCase("consumer") ==  0);
Reimeus
  • 158,255
  • 15
  • 216
  • 276
1

you can use custom messages, like this:

assertTrue("Value of d["+d+"] is not equal to consumer", (d.toName().compareToIgnoreCase("consumer") == 0));
Iłya Bursov
  • 23,342
  • 4
  • 33
  • 57