Eclips常用快捷鍵
alt + / 內(nèi)容提示
ctrl +1 快速修復(fù)
導(dǎo)包: ctrl + shift +O
格式化代碼: ctrl + shift +F
向前向后: alt + 方向鍵
添加注釋: ctrl +shift +/
除去注釋:ctrl + shift +
程序的調(diào)試和運(yùn)行
F5跳入 F6跳過 F7跳出
Junit 測試方法
新建類后可以通過新建測試類在測試方法生命行的上面加上@Test并導(dǎo)入Junit類即可運(yùn)行是選擇Junit測試兔朦。測試結(jié)果如圖:
Junit測試成功
附上測試代碼如下:
package hello;
public class cc {
public void XSS()
{
System.out.println("XSS");
}
public void Sql()
{
System.out.println("SQL");
}
}
測試類內(nèi)容如下:
package hello;
import org.junit.Test;
public class run {
@Test
public void ttten()
{
cc c = new cc();
c.XSS();
c.Sql();
}
}
Junit測試可以通過選擇某個(gè)函數(shù)單獨(dú)測試指定函數(shù)猿涨,如下圖:
單獨(dú)測試DVD類
DVD類代碼如下:
package hello;
public class DVD extends Item{
private String director;
public DVD(String title, String director, int playingTime, String comment) {
//super();
super(title,playingTime,comment);
this.director = director;
// this.playingTime = playingTime;
// this.comment = comment;
}
public void print() {
// TODO Auto-generated method stub
super.print();
System.out.println("==============="+director);
}
}
Junit測試可以使用@before參數(shù)示括,使其每個(gè)測試函數(shù)在開始前先執(zhí)行before函數(shù)里定義的內(nèi)容代碼罪佳。
After 在測試代碼執(zhí)行后會(huì)自動(dòng)執(zhí)行After聲明的代碼如圖:
Before及After輸出結(jié)果
參考代碼如下:
package hello;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class run {
@Before
public void fast()
{
System.out.println("fast");
}
@Test
public void ttten()
{
cc c = new cc();
c.XSS();
c.Sql();
}
@Test
public void runDVD()
{
DVD dvd=new DVD("dvd1", "DVD fast 1", 90, "bbbbbbbb");
dvd.print();
dvd.check();
}
@After
public void showx()
{
System.out.print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
}
}