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

@Mocked修饰对象放在方法中报错 #38

Open
aayii2015 opened this issue Jun 30, 2020 · 0 comments
Open

@Mocked修饰对象放在方法中报错 #38

aayii2015 opened this issue Jun 30, 2020 · 0 comments

Comments

@aayii2015
Copy link

站点中的学习示例
链接地址:http://jmockit.cn/showArticle.htm?channel=2&id=6

//@mocked@Injectable的不同
public class MockedAndInjectable {

@Test
public void testMocked(@Mocked Locale locale) {
    // 静态方法不起作用了,返回了null
    Assert.assertTrue(Locale.getDefault() == null);
    // 非静态方法(返回类型为String)也不起作用了,返回了null
    Assert.assertTrue(locale.getCountry() == null);
    // 自已new一个,也同样如此,方法都被mock了
    Locale chinaLocale = new Locale("zh", "CN");
    Assert.assertTrue(chinaLocale.getCountry() == null);
}

@Test
public void testInjectable(@Injectable Locale locale) {
    // 静态方法不mock
    Assert.assertTrue(Locale.getDefault() != null);
    // 非静态方法(返回类型为String)也不起作用了,返回了null,但仅仅限于locale这个对象
    Assert.assertTrue(locale.getCountry() == null);
    // 自已new一个,并不受影响
    Locale chinaLocale = new Locale("zh", "CN");
    Assert.assertTrue(chinaLocale.getCountry().equals("CN"));
}

}

报错如下:
MockedAndInjectable.testInjectable(Locale)
initializationError(org.junit.runner.manipulation.Filter)
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=testInjectable(java.util.Locale)], {LeadingIdentifierMatcher:fClassName=java.util.Locale,fLeadingIdentifier=testInjectable]] from org.junit.internal.requests.ClassRequest@d2cc05a

at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:80)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:71)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant