0

I've got a problem while testing my app, class "DateToday" exactly, here's part of that class:

public DateToday(){
    monthName();
    dayName();
    dayNumber();
    yearNumber();
}

public int yearNumber(){
    year = c.get(Calendar.YEAR);
    return year;
}

And here's my test class:

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class DateTodayTest {

private DateToday mDateToday;

@Test
public void checkYear() {
    assertEquals(mDateToday.yearNumber(), 2016);
}

Why I am still having NullPointerException at checkYear() method and the test is failed? It may be a stupid issue but I am blind with that...

Tymek T.
  • 135
  • 1
  • 5
  • 14

2 Answers2

1

It seems mDateToday is not initialized, you should use the constructor:

private DateToday mDateToday =  new DateToday ();
SCouto
  • 7,808
  • 5
  • 32
  • 49
0

You need to create new instance of DateToday class before calling assertEquals() method like: mDateToday = new DateToday();

Vladimir Vagaytsev
  • 2,871
  • 9
  • 33
  • 36