JAVA单元测试框架-6-Enable priority

  1.enabled属性

   在Testng中,如果方法前面添加了@Test注释,然后没有其他的属性,那么默认这个用例会被自动运行。当测试用例没有书写完成,或者不想测试时,可以采用注解@Test(enable=false)来禁止测试用例的执行。Enable属性有两个值true和false。

  @Test(timeOut = 3000,enabled = false)
    public void loginTest(){
        try{
            Thread.sleep(3100);
        }catch (InterruptedException e){
            System.out.println(e.toString());
        }
    }
    @Test
    public void testenable(){
        System.out.println("测试enable");
    }

跳过上面的loginTest测试

 

2.优先级设置priority

有时候,我们更希望,一个类文件下的测试用例按照我们设想的顺序去执行,而不是默认按照方法名的字母排序去执行。

@Test注释中有一个属性,叫priority支持设置用例的优先级。如果不带这个属性,默认priority是等于0,而且priority值越小,优先级越高。来看看下面的举例。

import org.testng.Reporter;
import org.testng.annotations.Test;

public class TestPriority {
	@Test(description="优先级" ,priority= 10)
	public void TestpriorityAdd() {
		Reporter.log(String.valueOf(11+12));
	}
	@Test(description="优先级" ,priority= 2)
	public void Testprioritysub() {
		Reporter.log(String.valueOf(21-12));
	}
	@Test(description="优先级" ,priority= 5)
	public void TestpriorityCat() {
		Reporter.log("cat 喵喵");
	}
	@Test(description="优先级" ,priority= 4)
	public void TestprioritypDog() {
		Reporter.log("dog  汪汪");
	}
	
	@Test(description="优先级" ,priority= 8)
	public void TestpriorityEnglish() {
		Reporter.log("good English");
	}
	@Test(description="优先级" ,priority= 1)
	public void TestpriorityChinese() {
		Reporter.log("good Chinese");
	}
	
	
}

 

PS D:\Android\skin2> ./gradlew build --info WARNING: A restricted method in java.lang.System has been called WARNING: java.lang.System::load has been called by net.rubygrapefruit.platform.internal.NativeLibraryLoader in an unnamed module (file:/C:/Users/86177/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/native-platform-0.22-milestone-28.jar) WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module WARNING: Restricted methods will be blocked in a future release unless native access is enabled Initialized native services in: C:\Users\86177\.gradle\native Initialized jansi services in: C:\Users\86177\.gradle\native Found daemon DaemonInfo{pid=25984, address=[98f52f11-5422-4822-a531-517066b0e039 port:43222, addresses:[/127.0.0.1]], state=Idle, lastBusy=1761229107209, context=Defaul tDaemonContext[uid=05f9d51e-3dfa-44e0-b71f-69781af5ef3b,javaHome=D:\Program Files\Android\Android Studio\jbr,javaVersion=21,javaVendor=JetBrains s.r.o.,daemonRegistryDi r=C:\Users\86177\.gradle\daemon,pid=25984,idleTimeout=10800000,priority=NORMAL,applyInstrumentationAgent=true,nativeServicesMode=ENABLED,daemonOpts=-Xmx2048m,-Dfile.encoding=UTF-8,-Duser.country=CN,-Duser.language=zh,-Duser.variant]} however its context does not match the desired criteria. JVM is incompatible. Wanted: DaemonRequestContext{jvmCriteria=D:\Program Files\Java\jdk-24 (no JDK specified, using current Java home), daemonOpts=[-Xmx2048m, -Dfile.encoding=UTF-8, -Duser.country=CN, -Duser.language=zh, -Duser.variant], applyInstrumentationAgent=true, nativeServicesMode=ENABLED, priority=NORMAL} Actual: DefaultDaemonContext[uid=05f9d51e-3dfa-44e0-b71f-69781af5ef3b,javaHome=D:\Program Files\Android\Android Studio\jbr,javaVersion=21,javaVendor=JetBrains s.r.o.,da emonRegistryDir=C:\Users\86177\.gradle\daemon,pid=25984,idleTimeout=10800000,priority=NORMAL,applyInstrumentationAgent=true,nativeServicesMode=ENABLED,daemonOpts=-Xmx2048m,-Dfile.encoding=UTF-8,-Duser.country=CN,-Duser.language=zh,-Duser.variant] Looking for a different daemon... The client will now receive all logging from the daemon (pid: 39468). The daemon log file: C:\Users\86177\.gradle\daemon\8.13\daemon-39468.out.log Starting 4th build in daemon [uptime: 25 mins 44.983 secs, performance: 100%, GC rate: 0.00/s, heap usage: 0% of 2 GiB] Using 16 worker leases. Now considering [D:\Android\skin2] as hierarchies to watch Watching the file system is configured to be enabled if available File system watching is active Starting Build Settings evaluated using settings file 'D:\Android\skin2\settings.gradle.kts'. Projects loaded. Root project using build file 'D:\Android\skin2\build.gradle.kts'. Included projects: [root project 'skin', project ':app'] > Configure project : Evaluating root project 'skin' using build file 'D:\Android\skin2\build.gradle.kts'. Resolved plugin [id: 'com.android.application', version: '8.13.0', apply: false] > Configure project :app Evaluating project ':app' using build file 'D:\Android\skin2\app\build.gradle.kts'. Resolved plugin [id: 'com.android.application', version: '8.13.0'] Using default execution profile All projects evaluated. Task name matched 'build' Selected primary task 'build' from project : FAILURE: Build failed with an exception. * What went wrong: Could not determine the dependencies of task ':app:test'. > Could not create task ':app:testDebugUnitTest'. > Could not create task of type 'AndroidUnitTest'. > Could not create an instance of type org.gradle.api.internal.tasks.testing.DefaultTestTaskReports. > Could not create an instance of type org.gradle.api.reporting.internal.DefaultReportContainer. > Type T not present * Try: > Run with --stacktrace option to get the stack trace. > Run with --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. BUILD FAILED in 3s
最新发布
10-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员路同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值