当前位置:网站首页>JUnit test suite method sorting (method 2 is not easy to use)
JUnit test suite method sorting (method 2 is not easy to use)
2022-06-12 14:42:00 【Micro blog】
Test suite usage method 1 : There is no need to inherit
Be careful : Use it directly @SuiteClasses Node can execute multiple junit Use cases , As shown below , none_password.class, none_username.class It's all written junit class , Use a comma to separate them , The code is as follows
// Perform multiple unit tests
@RunWith(Suite.class)
@SuiteClasses({ none_password.class, none_username.class})
public class alltest {
}
Test suite usage method 2 :
Use the kit testsuite Multiple... Can be executed at once junit Test class , The usage is as follows
( Test class inheritance TestCase): 1、 Executes testJ2.class Inheritance TestCase 2、testJ2.class The test method in should be based on test( A lowercase letter ) start ( Otherwise you can't recognize junit, Report errors No tests found in) 3、 If there is some input or setup And so on. , Can be added to the front of the kit
package testforliuxw;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class TestAll{
public static Test suite(){
TestSuite suite = new TestSuite();
suite.addTestSuite(testJ2.class);
suite.addTestSuite(testJmeter.class);
return suite;
}
}


Test suite usage method 3 : Test methods can be filtered
Category:Category Also inherited from Suit,Category It seems to be Suit The enhanced , It and Suit It also provides the ability to organize several test case classes into a group , In addition, it can group test cases , Give you the opportunity to select only some of the use cases you need . First, we build two interface classes for the grouping of our test methods , as follows
public interface Inter1 {
}
public interface Inter2 {
}
Then we classify the corresponding test methods in the class where our test methods are located
test2 All methods in the class belong to Inter1 and Inter2 Two groups
@Category({Inter1.class,Inter2.class})
public class test2{
@Test
public void testxiao()
{
int i=1;
assertEquals(1, i);
}
}
test1 The first method in the class belongs to Inter1 Group , Second method Inter2 Belong to two groups
public class test3{
@Category(Inter1.class)
@Test
public void testx()
{
int i=1;
assertEquals(1, i);
}
@Category(Inter2.class)
@Test
public void testxi()
{
int i=1;
assertEquals(2, i);
}
}
New test All3Test class , Added @IncludeCategory Limit only to Inter1 The use case , The running screenshot is as follows . Again Category And support @ExcludeCategory Annotations are used to exclude use cases , Use consistent , as follows , Only executed test3 Class
@RunWith(Categories.class)
@ExcludeCategory(Inter2.class)
@SuiteClasses({
test2.class,
test3.class
})
public class All3Test {
}
come from <http://lxw198902165221.blog.163.com/blog/static/25895002220164171042455/>
边栏推荐
- Junit异常情况,断言异常信息不为空过的方法
- 完美收官|详解 Go 分布式链路追踪实现原理
- Junit测试中常用的断言
- 工业机械臂(机器人)视觉定位引导系统
- Tcp/ip network communication knowledge record
- 【MySQL】数据库基本操作
- C secret arts script Chapter 5 (structure) (Section 1)
- 【Environment】1. Get the configuration in YML through the environment in the configuration class
- Player practice 19 xaudio turn on audio
- MobileOne: 移动端仅需1ms的高性能骨干,你值得拥有!
猜你喜欢

启明云端分享| 通过Matter协议实例演示开关通过matter协议来做到对灯亮灭的控制

Huawei equipment configuration BGP as number replacement

Interview (XI) futu written test questions

Analysis of two-dimensional array passing as function parameter (C language)

数据的收集

JMeter (V) pressure test of Excel file upload interface

sql跨库注入

Ppt cannot be opened, always prompt how to fix it

亿纬锂能拟募资90亿:刘金成骆锦红夫妇合计认购60亿 布局光谷
![[wechat applet] 4 Introduction to wechat developer tools](/img/9d/0d6c5cc675fb70dde98b25649bd8d8.jpg)
[wechat applet] 4 Introduction to wechat developer tools
随机推荐
数据的收集
QT multi thread drawing and real-time refreshing method
[ROC] aspriseocr C # English, Digital identification (not Chinese)
Tcp/ip network communication knowledge record
能链智电登陆纳斯达克:贝恩是股东 成中国充电服务第一股
我愿称之为史上最全的深度学习面经总结(附答案详解)
Producers (send syncask requests) and consumers (with xxxask monitoring and Implementation)
Player practice 20 audio thread and video thread
Module VIII
Vs2012: cannot assign a value of type 'char *' to an entity of type 'lpwstr'
Can you believe it? It took me only two days to develop a management system
Unhandled exception stack overflow
Player actual combat 14 display YUV
Player actual combat 25 unpacking module add close
【SimpleDateFormat】1. Conversion of date type and text type 2 Thread unsafe
[wechat applet] 6.1 applet configuration file
How to set, reset and reverse bit
Common DOS commands
MobileOne: 移动端仅需1ms的高性能骨干,你值得拥有!
Junit异常情况,断言异常信息不为空过的方法