我是单元测试的新手。我有一堂课可以打电话 .setUserName(...)。setUserID(...)。toJson如何对此进行JUnit测试?
public class Event{
private String userName;
private int userID;
private String userAddress;
public Event setUserName(String userName){
this.userName = userName;
return this;
}
public Event setUserID(String userID){
this.userID = userID;
return this;
}
public Event setUserAddress(String userAddress){
this.userAddress = userAddress;
return this;
}
public JSONObject toJson(){
JSONObject json = new JSONObject();
if(null != userName)
json.put("userName", userName);
if(0 != userID)
json.put("userID", userID);
if(null != userAddress)
json.put("userAddress", userAddress);
return json;
}
}
我需要测试每种设置方法吗?像
@Test
public void testSetUserName() {
Event event = new Event();
Assert.IsNotNull(event.setUserName("somename"));
}
我不确定。