-2

My code for junit is

@Autowired
private ABC abc;

@Test
public void checkZonePresent() {
    assertThat(abc.getZoneList().size()).isEqualTo(1);
}

SO, here I am getting error like java.lang.nullpointer exception

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
prasanna
  • 37
  • 1
  • 6
  • Have a look at this https://stackoverflow.com/questions/21878714/how-to-write-junit-test-with-spring-autowire – Morvader Jun 08 '17 at 07:36

1 Answers1

0

At first glance abc.getZoneList() is null. But also NPE might if you didn't configured tests with spring (didn't ). It's difficult to say without code , show pls how you configured test class

zero step (in your case it helps , but in general you don't need to test it if you configured spring tests) :

assertThat(abc ,is(notNullValue());

First you should check that :

assertThat(abc.getZoneList(),is(notNullValue());

and looks like ,abc.getZoneList() ,it's a problem the next check should be

assertThat(abc.getZoneList().size()).isEqualTo(1)

your test fail and there is no explanation why, but test should explains what's going wrong

xyz
  • 5,228
  • 2
  • 26
  • 35