183
社区成员
发帖
与我相关
我的任务
分享
|
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.
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 :

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.
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.
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.
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.