一、debug斷點(diǎn)調(diào)試
在代碼中,找一個(gè)位置,點(diǎn)擊
前面出現(xiàn)紅色點(diǎn):這個(gè)叫斷點(diǎn)
右擊鼠標(biāo),選擇Debug運(yùn)行
下圖:鼠標(biāo)懸停上面,會(huì)提示如下
1、Step Over(F8):點(diǎn)擊這個(gè)按鈕,或者按住F8鍵,可以往后面執(zhí)行
2、Step Into(F7):可以進(jìn)入方法內(nèi)部,如果當(dāng)前執(zhí)行到方法調(diào)用,就可以進(jìn)入方法內(nèi)部
3、Force Step Info(Alt+Shift+F7):強(qiáng)制進(jìn)入方法內(nèi)部
4、Step Out(Shift +F8):退出執(zhí)行的方法,也就是返回
5、Run to Cusor(Alt+F9):調(diào)到下一個(gè)斷點(diǎn)
6:、Rerun(Ctrl+F5):重新執(zhí)行
7、Resume Program(F9):跳到下一個(gè)斷點(diǎn)
8、Stop(Crto+F2):停止程序
9、View Breakpoints(Ctrl+Shift+F8):查看有哪些斷點(diǎn)
10、Mute Breakpoints:禁止斷點(diǎn),下次debug啟動(dòng),不會(huì)執(zhí)行斷點(diǎn),因?yàn)橐呀?jīng)被禁止了
查看斷點(diǎn)
禁止斷點(diǎn)
可以查看到變量值
Evaluate Expression:debug過(guò)程中,可以執(zhí)行表達(dá)式文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-829183.html
二、junit單元測(cè)試
第一步:導(dǎo)入junit包,在項(xiàng)目下創(chuàng)建lib包
第二步:將junit包拷貝到lib目錄下
第三步:File->Project Structure
第四步:找到剛剛的junit jar包
測(cè)試代碼文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-829183.html
package com.day04;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TestJunit {
String url = "jdbc:mysql://localhost:3306/tmall";
String username = "root";
String password = "root";
int port = 3306;
boolean flag = false;
/**
* 測(cè)試方法執(zhí)行之前執(zhí)行
*/
@Before
public void connect(){
if("root".equals(username) && "root".equals(password)){
flag = true;
}
}
/**
* 測(cè)試方法執(zhí)行之后執(zhí)行
*/
@After
public void close(){
flag = false;
System.out.println("close...");
}
/**
* 測(cè)試
*/
@Test
public void test1(){
String name = "";
System.out.println("test....");
System.out.println(flag);
}
/**
* 執(zhí)行時(shí)間超過(guò)1000毫秒報(bào)錯(cuò)
*/
@Test(timeout = 1000)
public void test2(){
String name = "";
System.out.println("test....");
System.out.println(flag);
while(true){
System.out.println("x");
}
}
}
到了這里,關(guān)于Java語(yǔ)言基礎(chǔ)(4)IDEA程序debug斷點(diǎn)調(diào)試與單元測(cè)試junit(圖文簡(jiǎn)單超詳細(xì)教程,一文搞定debug斷點(diǎn)調(diào)試和junit單元測(cè)試)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!