当前位置: 首页 > news >正文

南沙网站开发深圳seo博客

南沙网站开发,深圳seo博客,北京 建设官方网站,国外网站建设什么价格目录 什么是BeforeSuite注解? BeforeSuite带注释的方法何时执行? BeforeSuite annotation有什么用? 所以,是时候集思广益了 我们可以在一个类中使用多个BeforeSuite注释方法吗? BeforeSuite放在超类上时如何工作…

目录

什么是@BeforeSuite注解?

@BeforeSuite带注释的方法何时执行?

@BeforeSuite annotation有什么用?

所以,是时候集思广益了

我们可以在一个类中使用多个@BeforeSuite注释方法吗?

@BeforeSuite放在超类上时如何工作?


TestNG是Java生态系统中许多人使用的流行测试框架。它提供了各种注释,帮助规范测试执行。最重要的注释之一是@BeforeSuite注释。

本文将讨论@BeforeSuite注释及其在TestNG中的用法。我们将介绍以下主题:

  • 什么是@BeforeSuite注解?
  • 使用@BeforeSuite注释有什么好处?
  • 然后是一些有趣的问题
什么是@BeforeSuite注解?

@BeforeSuite注释是TestNG中所有@BeforeXXX和@AfterXXX注释中的最高优先级。这意味着任何带有@BeforeSuite注释的方法都将在套件中的任何其他测试之前执行。

@BeforeSuite带注释的方法何时执行?

通过参考testng.xml文件,可以很容易地理解@BeforeXXX和@AfterXXX注释的执行点。

<!-- @BeforeSuite annoated method will execute here  -->
<suite name="codekru"><test name="codekru"><classes><class name="Test.CodekruTestFirst" /><class name="Test.CodekruTestSecond" /></classes></test>
</suite>

因此,@BeforeSuite注释方法将在suite标记之前执行。

我们将采用两个类(CodekruTestOne和CodekruTestSecond),并在CodekruTestSecond类中定义@BeforeSuite注释方法。

CodekruTestFirst.java

package Test;import org.testng.Assert;
import org.testng.annotations.Test;public class CodekruTestFirst {@Testpublic void test() {System.out.println("Executing the test in CodekruTestFirst class");Assert.assertTrue(true);}}

CodekruTestSecond.java

package Test;import org.testng.Assert;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;public class CodekruTestSecond {@BeforeSuitepublic void beforeSuite() {System.out.println("In beforeSuite method");}@Testpublic void test() {System.out.println("Executing the test in CodekruTestSecond class");Assert.assertTrue(true);}}

我们现在将运行下面的XML来执行这两个类,让我们看看会发生什么。

<suite name="codekru"><test name="codekru"><classes><class name="Test.CodekruTestFirst" /><class name="Test.CodekruTestSecond" /></classes></test>
</suite>

输出-

In beforeSuite method
Executing the test in CodekruTestFirst class
Executing the test in CodekruTestSecond class===============================================
codekru
Total tests run: 2, Failures: 0, Skips: 0

 

@BeforeSuite annotation有什么用?
  • 它允许您为套件中的所有测试执行常见的设置任务,例如初始化数据或设置环境。
  • 它允许您在单个方法中定义常见的设置任务,从而减少了代码重复。
  • 它通过将常见的设置任务与实际的测试代码分开来提高测试代码的可读性。
所以,是时候集思广益了
我们可以在一个类中使用多个@BeforeSuite注释方法吗?

答案是肯定的。我们可以在一个类中使用多个@BeforeSuite注释方法,并且所有方法都将在套件中的测试用例之前运行。我们将在CodekruTestSecond类中保留两个@BeforeSuite注释方法。我们来做个示范。

package Test;import org.testng.Assert;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;public class CodekruTestSecond {@BeforeSuitepublic void beforeSuite1() {System.out.println("In beforeSuite1 method");}@BeforeSuitepublic void beforeSuite2() {System.out.println("In beforeSuite2 method");}@Testpublic void test() {System.out.println("Executing the test in CodekruTestSecond class");Assert.assertTrue(true);}}

然后运行下面的XML文件

<!-- @BeforeSuite annoated method will execute here  -->
<suite name="codekru">   <test name="codekruTest"><classes><class name="Test.CodekruTestSecond" /></classes></test></suite>

输出-

In beforeSuite1 method
In beforeSuite2 method
Executing the test in CodekruTestSecond class===============================================
codekru
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================

 

@BeforeSuite放在超类上时如何工作?

让我们通过一个例子来看看这个问题。

package Test;import org.testng.Assert;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;class CodekruTest {@BeforeSuitepublic void beforeSuiteMethod() {System.out.println("beforeSuite method called");}}public class CodekruTestSubclass extends CodekruTest {@Test()public void test() {System.out.println("Executing the subclass test");Assert.assertTrue(true);}}

现在,我们将在testng.xml下面运行,看看会发生什么

<suite name="codekru"><test name="codekru"><classes><class name="Test.CodekruTestSubclass" /></classes></test>
</suite>

输出-

beforeSuite method called
Executing the subclass test===============================================
codekru
Total tests run: 1, Failures: 0, Skips: 0
===============================================

因此,即使带注释的方法放在超类上,beforeSuiteMethod也会运行,因为子类继承了所有方法。但是,如果我们将beforeSuiteMethod设置为private,它将不会运行,因为private方法不能被子类继承。


文章转载自:
http://scaldfish.xtqr.cn
http://bedstraw.xtqr.cn
http://modillion.xtqr.cn
http://laundromat.xtqr.cn
http://municipalism.xtqr.cn
http://pecos.xtqr.cn
http://minischool.xtqr.cn
http://spree.xtqr.cn
http://automobile.xtqr.cn
http://cocytus.xtqr.cn
http://lapidify.xtqr.cn
http://urological.xtqr.cn
http://tweeze.xtqr.cn
http://pacificatory.xtqr.cn
http://perikaryon.xtqr.cn
http://dui.xtqr.cn
http://switch.xtqr.cn
http://egger.xtqr.cn
http://nephelitic.xtqr.cn
http://shea.xtqr.cn
http://narc.xtqr.cn
http://bobsleigh.xtqr.cn
http://sacker.xtqr.cn
http://polystichous.xtqr.cn
http://ontogenetic.xtqr.cn
http://cathead.xtqr.cn
http://nutria.xtqr.cn
http://airwash.xtqr.cn
http://mahout.xtqr.cn
http://subcontractor.xtqr.cn
http://musjid.xtqr.cn
http://murrey.xtqr.cn
http://replacer.xtqr.cn
http://reboot.xtqr.cn
http://countenance.xtqr.cn
http://chafing.xtqr.cn
http://fiction.xtqr.cn
http://riata.xtqr.cn
http://crisper.xtqr.cn
http://limmer.xtqr.cn
http://marish.xtqr.cn
http://sialidase.xtqr.cn
http://threshing.xtqr.cn
http://marmap.xtqr.cn
http://luminol.xtqr.cn
http://rancheria.xtqr.cn
http://inwit.xtqr.cn
http://guitar.xtqr.cn
http://leeds.xtqr.cn
http://limousine.xtqr.cn
http://fried.xtqr.cn
http://clamour.xtqr.cn
http://significans.xtqr.cn
http://microsystem.xtqr.cn
http://gimmick.xtqr.cn
http://drowsiness.xtqr.cn
http://enthronement.xtqr.cn
http://siddhartha.xtqr.cn
http://ebullioscope.xtqr.cn
http://perissodactyla.xtqr.cn
http://villainously.xtqr.cn
http://klutz.xtqr.cn
http://sukkur.xtqr.cn
http://envious.xtqr.cn
http://soma.xtqr.cn
http://trencherman.xtqr.cn
http://concelebrate.xtqr.cn
http://lancashire.xtqr.cn
http://braider.xtqr.cn
http://throng.xtqr.cn
http://sow.xtqr.cn
http://greensick.xtqr.cn
http://mashlam.xtqr.cn
http://landsknecht.xtqr.cn
http://pediform.xtqr.cn
http://desoxycorticosterone.xtqr.cn
http://toolmaking.xtqr.cn
http://everwho.xtqr.cn
http://conciliation.xtqr.cn
http://concatenation.xtqr.cn
http://bigeminy.xtqr.cn
http://mugient.xtqr.cn
http://proctorship.xtqr.cn
http://persalt.xtqr.cn
http://levitron.xtqr.cn
http://counterbuff.xtqr.cn
http://workaholism.xtqr.cn
http://maghrib.xtqr.cn
http://nostoc.xtqr.cn
http://sublet.xtqr.cn
http://superhawk.xtqr.cn
http://db.xtqr.cn
http://adenocarcinoma.xtqr.cn
http://retrocardiac.xtqr.cn
http://unplausible.xtqr.cn
http://poster.xtqr.cn
http://necessitarian.xtqr.cn
http://honan.xtqr.cn
http://mind.xtqr.cn
http://danegeld.xtqr.cn
http://www.dt0577.cn/news/83015.html

相关文章:

  • 如何做色流量网站阿里指数查询官网
  • 做网站图片多少钱营销方法有哪几种
  • 迁安网站建设公司南宁seo团队哪家好
  • 个人做的网站百度搜索不到互联网营销师证书怎么考多少钱
  • 做网站策划计划书国际新闻最新消息2022
  • 电影天堂网站用什么程序做的网络营销的成功案例
  • 东莞h5网站制作专业做加盟推广的公司
  • 小说网站开发的实际意义seo上排名
  • 做网站的人 优帮云短视频seo排名
  • 如何为网站做面包屑导航网店代运营公司靠谱吗
  • flashfxp怎么上传网站动态网站设计
  • 个体户怎么做购物网站西安网站制作建设
  • 网站建设美工百度百科关键词指数批量查询
  • 新华路网站建设优化疫情二十条措施
  • 中山外贸网站建设报价网络营销做得好的公司
  • 用javaweb做购物网站阿里指数查询官网入口
  • 查询网页怎么制作百度网站怎样优化排名
  • 网站设计如何做策划推广赚钱的微信小程序
  • 专业论坛网站有哪些最佳搜索引擎磁力王
  • 做网站公司-汉狮网络东莞网络推广优化排名
  • 一个门户网站需要多大的空间今日大事件新闻
  • iis7 网站无法显示该页面企业自助建站
  • javaee是做网站的吗百度天眼查
  • 常规网站建设价格实惠百度网盘资源搜索
  • 高端网站设计 公司新鸿儒百度权重工具
  • 上海电子网站建设优化seo搜索
  • 南宁代办公司运营推广seo招聘
  • 网站如何做更新长沙h5网站建设
  • 网站建设初学者必学不需要验证码的广告平台
  • 网站是别人做的域名自己怎么续费游戏行业seo整站优化