当前位置:网站首页>Common assertions in JUnit testing

Common assertions in JUnit testing

2022-06-12 14:42:00 Micro blog

1、 Assert whether the captured exception information contains some string content     

 try {

//TODO

        } catch (Exception e) {

            StringWriter sw = new StringWriter();

            PrintWriter pw = new PrintWriter(sw);

            e.printStackTrace(pw);

            String msg = sw.toString();

            String exp = " Customer information does not exist , Do not modify ";

            Assert.assertNotEquals(-1, msg.indexOf(exp));

        }

2、 Asserts whether the caught exception is a specified exception

        try {

//TODO

        } catch (Exception e) {

            Assert.assertEquals(e.getClass(), RPCTimeoutException.class);

        } 

3、 Asserts whether the elapsed time is the specified time , among System.currentTimeMillis() Is to obtain the current system time ,start It's the start time

String taketime = Long.toString(System.currentTimeMillis() - start);

Assert.assertNotSame(-1, taketime.indexOf("10"));

Time to be consumed here (Long type ) convert to string After the type , Compare it with the estimated time

 

 

原网站

版权声明
本文为[Micro blog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206121418276046.html