[英]I have two methods that need to be tested using the JUnit test. Here are the codes
公共類經理擴展員工{
/**
* Manager Constructor takes in arguements and calls superclass
* @param id
* @param weeklyPay
*/
public Manager(int id, double weeklyPay) // Constructor
{
super(id);
super.weeklyPay=weeklyPay;
}
public String toString() // returns a String
{
return "Manager "+super.toString();
}
public double calculateWeeklyPay() // calculates weeklypay
{
return super.weeklyPay;
}
我一定要考toString方法和calculateWeeklyPay方法。 我該怎么做?
不確定您是否要測試該類,因為超級類中的邏輯看起來很多。 但是這里...
assertEquals(42d, new Manager(1, 42d).calculateWeeklyPay,0.001);
並測試字符串是否等於(假設super.toString
返回MyString
assertEquals("ManagerMyString", new Manager(1, 42d));
右側的toString
會自動調用,或者如果您想顯式地調用
assertEquals("ManagerMyString", new Manager(1, 42d).toString());
所有這些方法都是JUnit的一部分,可以通過Assert類靜態導入到Java文件中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.