EE308 LAB11

YY-nb YY-nb 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

 

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. 

 

  

 

 

...全文
评论
收藏 已收藏
分享
返回顶部