EE308 LAB11
|
The Link Your Class | |
|
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/603748107 |
|
The Aim of This Assignment |
Software Testing |
|
MU STU ID and FZU STU ID | 19103727&831902105 |
We test some functions of our back-end program.
1.Junit Assert
Some part of code:
@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class Test {
@Autowired
public INoteService noteService;
String noteId="e30f6e231b524b06b67403bf01f6f682";
String userId="xxx";
@org.junit.Test
/**
* 测试查询社区笔记
*/
public void testSelectCommunityNote(){
List<NoteInfoVo> noteInfoVoList = noteService.showNoteInCommunityPage(1, 1);
log.info(noteInfoVoList.toString());
Assert.assertNotNull(noteInfoVoList);
}
The result :

2. Junit Time Test
code:
@org.junit.Test(timeout = 1000)
public void testGetNoteDetail(){
Map<String, Object> noteDetail = noteService.getNoteDetail(noteId);
log.info(noteDetail.toString());
Assert.assertNotNull(noteDetail);
}
result:

Since the test case use 625 ms, which is lower than 1000 ms we set, the function pass the time out test.
3.Junit Parameterized Test
We test whether fastjson dependency can be successfully used and we try to test the function of geting the value of a Json-form string.
code:
@Slf4j
@RunWith(Parameterized.class)
@SpringBootTest
public class ParameterTest {
private String str;
@Parameterized.Parameters
public static Collection<Object> data() {
Object[] data = new Object[] {
"{\"name\":\"tom\",\"age\":\"12\"}",
"{\"name\":\"tom\",\"age\":\"13\"}",
"{\"name\":\"Jerry\",\"age\":\"12\"}"
};
return Arrays.asList(data);
}
public ParameterTest(String str){
this.str=str;
}
@Test
public void testJson(){
JSONObject jb=JSONObject.parseObject(str);
String s=jb.get("name").toString();
log.info(s);
Assert.assertEquals(s,"tom");
}
}
result:

Since the value of name we expect is "tom" and only two cases is "tom" while the other one is "Jerry", two cases are passed and one case fails.
4.Junit Exception Test
code:
@org.junit.Test(expected = CustomSqlException.class)
/**
* 测试更改笔记
*/
public void testEditNote(){
Note note=new Note();
note.setTitle("Test Edit")
.setContent("Edit the test")
.setNoteId(noteId);
ApiResult result = noteService.editNote(userId, note);
Assert.assertNotNull(result);
}
result:

Since we expect the program to throw CustomSqlException but the test fails, it means there is no CustomSqlException in our test function.
5.Junit Suite Test
code:
@Slf4j
@SpringBootTest
@RunWith(Suite.class)
@Suite.SuiteClasses({Test.class,ParameterTest.class})
public class SuiteTest {
}
result:

Two tests fail and four tests pass. The test result is the same as the former ones.
相关推荐
EE-308 LAB4 final version.7z
这是本次实验的压缩包
EE308-Lab11-Software Testing
unittest for Python
《模式识别与数据挖掘》配套PPT课件
《模式识别与数据挖掘》配套PPT课件
科技成果转化项目进场交易前,评估备案环节需要准备哪些材料?_8.docx
科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。
人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核
人工智能通识教育(中职版)课程标准+PPT课件+部分素材+电子活页+在线考核


