0
我已經寫過單個測試用例,但是我不知道我是否正確。如果你有更好的選擇,請給我建議。請幫助我編寫測試套件。如何編寫測試套件spring mvc project
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:WEB-INF/spring/appServlet/servlet-context.xml" })
public class TestHelper {
@Mock
private UserDaoImpl userDaoImpl;
@InjectMocks
private Helper helper;
private MockMvc mockMvc;
String msg = "Success";
int status = 200;
ResponseMessage message = new ResponseMessage();
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
this.mockMvc = MockMvcBuilders.standaloneSetup(helper).build();
}
@Test
public void testsavetoken() throws Exception {
Token token = new Token();
token.setAccessToken("ya29.WgJ2glWhvEfcP-YE0ndPlZY3NDXGGpoK5Zp4-l2qlCKkepLjQDHKO68dfopGjvhkM_QY");
token.setAuthToken("ya29.WgJ2glWhvEfcP-YE0ndPlZY3NDXGGpoK5Zp4-l2qlCKkepLjQDHKO68dfopGjvhkM_QY");
token.setSessionId("ya29.WgJ2glWhvEfcP-YE0ndPlZY3NDXGGpoK5Zp4-l2qlCKkepLjQDHKO68dfopGjvhkM_QY");
token.setUuid("test1");
when(userDaoImpl.saveToken(any(Token.class))).thenAnswer(new Answer() {
@Override
public Token answer(InvocationOnMock invocation) throws Throwable {
Token token1 = (Token) invocation
.getArguments()[0];
token1.setUuid("hhhhh");
return token1;
}
});
message = helper.registerToken(token);
assertNotNull(message);
Assert.assertEquals(status, message.getStatus());
Assert.assertEquals(msg, message.getMessage());
}
}
但是現在我很興奮地編寫測試套件,所以我無法添加更多的測試用例!
感謝諮詢我,我也做了單元測試,因爲我已經做了單獨測試控制器,助手和DAO layer.but IM迷茫的時候我寫的測試套件它。我需要多創建測試套件以及我可以在其上應用哪種類型的測試套件。 – shailu