当前位置:网站首页>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/>
边栏推荐
- selenium进阶
- 【SimpleDateFormat】1. Conversion of date type and text type 2 Thread unsafe
- Printing colored messages on the console with printf
- ADB command (I) record
- Two months' experience in C language
- selenium-webdriver之断言
- Player practice 18 xresample
- Soft test (VI) Chrome browser installation selenium IDE
- C语言中主函数调用另外一个函数,汇编代码理解
- Player practice 20 unpacking thread
猜你喜欢

【OCR】AspriseOCR C# 英文、數字識別(中文不行)

QT multi thread drawing and real-time refreshing method

Introduction to QT reflection mechanism and signal slot mechanism

Tcp/ip network communication knowledge record

JS (III) convert ES6 syntax to Es5 syntax

Can you believe it? It took me only two days to develop a management system
![[wechat applet] 3 The first wechat applet](/img/40/1571c11363e72f5a1e932586a1f240.jpg)
[wechat applet] 3 The first wechat applet

掌门教育被强制退市:上市仅一年时间 软银CMC损失惨重

Machine learning learning notes

启明云端分享| 通过Matter协议实例演示开关通过matter协议来做到对灯亮灭的控制
随机推荐
Energy chain smart electronics landed on NASDAQ: Bain is the shareholder to become the first share of charging services in China
[wechat applet] 1 Introduction to wechat applet
掌门教育被强制退市:上市仅一年时间 软银CMC损失惨重
C語言中主函數調用另外一個函數,匯編代碼理解
能链智电登陆纳斯达克:贝恩是股东 成中国充电服务第一股
[wp][入门]攻防世界-game
Producers (send syncask requests) and consumers (with xxxask monitoring and Implementation)
selenium进阶
MAT的安装和使用
完美收官|详解 Go 分布式链路追踪实现原理
【Instant】1. Equivalent to date class 2 Represents a moment
JS (I) error [err\u module\u not\u found]: cannot find package 'UUID' imported
Mysql之索引和视图
你敢信?开发一个管理系统我只用了两天
PMP敏捷知识点
【Optional】1. Map and ifpresent 2 Ofnullable and orelse
Copy word content to excel and automatically divide it into multiple columns
[Writeup]BUU SQL COURSE1[入门级]
And, or, not equal, operator
Reverse the encryption parameters of a hot water software