1
我想模擬編寫單元測試的gae用戶服務,並且無法獲得以下代碼來工作。無法模擬GAE用戶服務
我的測試課程如下。
public class AuthenticationTest {
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalUserServiceTestConfig())
.setEnvIsAdmin(true).setEnvIsLoggedIn(true)
.setEnvEmail("[email protected]");
@Before
public void setUp() {
helper.setUp();
}
@After
public void tearDown() {
helper.tearDown();
}
@Test
public void testIsAdmin() {
UserService userService = UserServiceFactory.getUserService();
assertTrue(userService.isUserAdmin());
String email = userService.getCurrentUser().getEmail();
assertEquals(email, "[email protected]");
}
}
我發現userService.getCurrentUser()總是返回null。
大部分代碼取自developers.google.com中的示例。我添加的唯一的東西是呼叫.setEnvEmail(「[email protected]」)
任何幫助,將不勝感激。
感謝,
沙迪亞
您的'@ Before'方法正在運行嗎? – 2013-05-12 08:20:03
是的,我把一個斷點,並確認@Before方法正在運行。 – Sathya 2013-05-12 09:14:45