New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking static methods and instances from the same class doesn't work with TestNG #82

Closed
helmbold opened this Issue Oct 1, 2014 · 0 comments

Comments

2 participants
@helmbold

helmbold commented Oct 1, 2014

The following example doesn't work with TestNG 6.8.8, JMockit 1.12 and Java 1.8.0_20.

public class DateUser {

  public static boolean isLunchTime() {
    int hour = LocalDateTime.now().getHour();
    return hour >= 12 && hour <= 14;
  }
}

public class DateUserTest {

  @Test
  public void shouldReturnTrueFor12h(@Mocked LocalDateTime dateTime) {
    new Expectations() {{
      LocalDateTime.now(); result = dateTime;
      dateTime.getHour(); result = 12;
    }};

    boolean isLunchTime =  DateUser.isLunchTime();

    assertThat(isLunchTime).isTrue();
  }
}

It works only with JUnit.

@rliesenfeld rliesenfeld added the bug label Oct 1, 2014

@rliesenfeld rliesenfeld self-assigned this Oct 1, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment