新建測試類,因爲方法內容涉及到shiro和數據庫操作,被卡了數小時,這裏記錄一下成功方案
(因爲使用的是bootdo框架,框架已添加了所需依賴,未添加依賴的記得添加到pom文件)
在需要新建測試類的類中右鍵
出現下圖,點擊即可
點擊ok
(紅框處選中則生成的測試類中有該方法)
測試類代碼:
package XXX;
import org.apache.shiro.util.ThreadContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ProjectFontControllerTest {
@Resource
org.apache.shiro.mgt.SecurityManager securityManager;
@Before
public void setUp() throws Exception {
ThreadContext.bind(securityManager);
}
@Autowired
ProjectService projectService;
@Test
public void addProject() { //自動生成的方法名,也可自定義
//代碼,非自動生成
}
}
點擊函數方法左側的運行按鈕即可
運行完成後點擊查看運行結果