Skip to content
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

helmbold opened this issue Oct 1, 2014 · 0 comments


Copy link

@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 =;
    return hour >= 12 && hour <= 14;

public class DateUserTest {

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

    boolean isLunchTime =  DateUser.isLunchTime();


It works only with JUnit.

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

No branches or pull requests

2 participants