EE308 LAB11

YY-nb 2021-12-14 10:49:03

 

The Link Your Class

https://bbs.csdn.net/forums/MUEE308FZ

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. 

 

  

 

 

...全文
202 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

183

社区成员

发帖
与我相关
我的任务
社区描述
福州大学 梅努斯国际工程学院 软件工程 教学
软件工程 高校
社区管理员
  • 单步调试
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧