TestNG测试用例

解决TestNG测试用例依赖性的问题 如果测试用例间有依赖性,也就是如果想执行B,就必须要先执行A。那么用例的执行顺序就很关键,如何来指定用例的顺序呢,有这样几种方法: 1. 给用例加编号: public void test01Login(){ XXX } public void test02Add(){ XXX } public void test03Delete(){ XXX } 2. 加上关键字 硬依赖的 阅读详情

使用TestNG的第一个测试用例

要遵循的步骤:

1)按Ctrl + N,在TestNG类别下选择“ TestNG Class ” ,然后单击Next。

要么

右键单击Test Case文件夹,转到TestNG并选择“ TestNG Class ”。

TestNG的-FTC-1

2)如果您的项目已设置并且您在创建TestNG类之前选择了“测试用例”文件夹,则源文件夹和包名称将在表单上预先填充。将类名设置为“ TestNG ”。

在Annotations下,选中“ @BeforeMethod ”,“ @ AfterMethod ”并单击Finish。而已。

TestNG的-FTC-2

3)现在它将在Test Case包(文件夹)下显示新创建的TestNg类。TestNG类看起来像下面的图像,显​​示三个空方法。一个方法f()默认情况下和方法之前和之后,在创建类时选择。

TestNG的-FTC-3

4)Project Explorer将使用TestNG类看起来像这样。

 

TestNG的-FTC-4

现在是时候编写第一个TestNG测试用例了。

5)让我们以第一个测试用例为例,将测试用例分为三个部分。

@BeforeMethod:启动Firefox并将其指向基本URL

@Test:输入登录用户名和密码,打印控制台消息并注销

@AfterMethod:关闭Firefox浏览器

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

package automationFramework;

 

import java.util.concurrent.TimeUnit;

 

import org.openqa.selenium.By;

 

import org.openqa.selenium.WebDriver;

 

import org.openqa.selenium.firefox.FirefoxDriver;

 

import org.testng.annotations.Test;

 

import org.testng.annotations.BeforeMethod;

 

import org.testng.annotations.AfterMethod;

 

public class TestNG {

 

public WebDriver driver;

 

  @Test

 

  public void main() {

 

// Find the element that's ID attribute is 'account'(My Account)

 

      driver.findElement(By.id("account")).click();

 

      // Find the element that's ID attribute is 'log' (Username)

 

      // Enter Username on the element found by above desc.

 

      driver.findElement(By.id("log")).sendKeys("testuser_1");

 

      // Find the element that's ID attribute is 'pwd' (Password)

 

      // Enter Password on the element found by the above desc.

 

      driver.findElement(By.id("pwd")).sendKeys("Test@123");

 

      // Now submit the form. WebDriver will find the form for us from the element

 

      driver.findElement(By.id("login")).click();

 

      // Print a Log In message to the screen

 

      System.out.println(" Login Successfully, now it is the time to Log Off buddy.");

 

      // Find the element that's ID attribute is 'account_logout' (Log Out)

 

      driver.findElement(By.id("account_logout"));

 

  }

 

  @BeforeMethod

 

  public void beforeMethod() {

 

  // Create a new instance of the Firefox driver

 

      driver = new FirefoxDriver();

 

      //Put a Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception

 

      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

 

      //Launch the Online Store Website

 

      driver.get("http://www.onlinestore.toolsqa.wpengine.com");

 

  }

 

  @AfterMethod

 

  public void afterMethod() {

 

  // Close the driver

 

      driver.quit();

 

  }

 

}

6)右键单击测试用例脚本运行测试,然后选择Run As > TestNG Test。

TestNG的-FTC-5

 

运行Testng测试用例的结果

7)完成执行几分钟后,一旦完成,结果将在TestNg Result窗口中显示如下。

TestNG的-FTC-6

它显示'传递:1'。这意味着测试成功并通过。

有3个子标签。“所有测试”,“测试失败”和“摘要”。只需单击“所有测试”即可查看其中的内容。

TestNG的-FTC-7

如您所见,有关于执行哪些测试用例及其持续时间的信息。看看其他标签。比Junit好吗?

8)TestNG还生成HTML报告。要访问这些报告,请转到Project目录并打开test-output文件夹。

TestNG的-FTC-8

9)打开' emailable-report.html ',因为这是一个用浏览器打开它的html报告。

TestNG的-FTC-9

10)TestNG还生成' index.html '报告,它位于同一个测试输出文件夹中。此报告提供指向TestNG报告的所有不同组件(如组和报告输出)的链接。单击这些将显示执行的详细描述。在TestNG的高级章节中,我们将介绍每个TestNG主题。

TestNG的-FTC-10

TestNG的-FTC-11

TestNG组织测试用例的最佳实践 在目前的工作中,经常需要写大量的测试用例(Test Case),然后用TestNG进行自动化测试。随着test case数量的不断增加,发现目前写test case的方法存在一些不足之处。经过几天的思考和探索,找到一种充分利用TestNG的testng.xml配置文件组织test case的方法。 阅读详情

相关推荐

如何在TestNG中恢复失败的测试用例?

有时,案例失败,不是因为应用程序错误,而是因为意外事件,如浏览器问题,网络滞后等,现在,我们可能需要重新验证失败的案例,看看这些意外事件是否仍然存在。现在,有两个用例失败了(test 2和test 3),并且必须在testng-output中创建一个testng-failed.xml文件,该文件可用于运行失败的测试用例。但是有时候,我们不想把重试算在所有的用例中,而只想显示在我们的测试类中已经写好的用例的数量。您可能已经注意到,每当我们重试案例时,我们的总案例数就会增加,跳过的案例数也会增加。

C'mon的博客 1777

testng编写测试用例

TestNG TestNG是一个测试框架,是java 最常用的测试工具,从单元测试到集成测试都在使用。 TestNG编写测试通常需要三个步骤: 编写测试的业务逻辑并在代码中插入TestNG注释。 在testng.xml文件或build.xml中添加有关测试的信息(例如类名、要运行的组等)。 运行TestNG。 代码例子: package com.example.batch...

keny-大成的博客 819

如何在TestNG中忽略测试用例

但是,我们不能只是将@Ignore注释放在包的顶部,如下面的代码所示。在这篇文章中,我们将讨论如何在TestNG中忽略测试用例。TestNG帮助我们忽略使用@Test注释的情况,我们可以在不同的级别上忽略这些情况。因此,如果我们在一个类上放置@Ignore注释,那么该类及其子类中的case将被忽略。所以,现在在这个文件中,我们可以在Test包上写@Ignore,如下所示。注意:@Ignore注释的优先级高于单个@Test方法注释。这里,子类的case没有执行,因为我们在父类上使用了@Ignore注释。

C'mon的博客 1312

Java自动化用例管理利器 —— TestNG详解

TestNG是开源自动化测试工具,覆盖多类型测试:单元测试,功能测试,集成测试,它的功能非常强大,支持多种类型的单元测试(异常测试, 超时测试,依赖测试….)支持参数化& 提供了丰富的测试用例组织方式(Suite, Test, Method)生成测试报告,并支持测试报告扩展(Allure,ReportNG)

myh919的博客 1235

如何在TestNG中获取运行时的测试用例细节?

例如,我们可以使用onTestSuccess()方法来检索基本数据点,例如测试用例结果、运行时信息和其他相关细节,只要测试用例被标记为通过。通过利用这些功能,我们可以获得对自动化测试套件性能的有价值的洞察,并获得测试条件下应用程序行为的详细视图。我们只使用了onTestSuccess()方法,但根据您的需求,您可能还希望使用其他方法,例如onTestStart()或onTestFailure()。我们可能在不同的场景中需要这些信息,比如创建定制的报告或者开发一个实时跟踪系统来监视测试用例的进度。

C'mon的博客 711

拌合楼软件开发(24)接收微信消息生成车辆计划

【摘要】针对拌合站客户群体文化程度不高、习惯微信群沟通的业务场景,提出通过企业微信机器人实现微信对话下单的解决方案。核心是利用WorkTool工具的消息回调机制:1)配置接收消息的API接口;2)解析JSON格式的对话数据,筛选@机器人的有效消息;3)采用*号分隔符提取订单信息并进行校验;4)建立微信昵称与客户系统的映射关系。方案解决了传统系统登录门槛高的问题,但需注意群名唯一性、多系统对接及客户身份识别等关键问题。全文重点阐述技术实现逻辑而非具体代码。

morsth的博客 1045

TestNG提供的标注详解

为了开发测试用例,TestNG提供了大量的标注annotations。本文只是提供对TestNG标注的一览,具体用法见后续文章。 @BeforeSuite,修饰一个方法,在testng.xml中的之前执行@AfterSuite,修饰一个方法,在testng.xml中的之后执行@BeforeTest,修饰一个方法。对于该方法所在的testng.xml中的,其中涉及到的所有测试类的所有测试方

成长的足迹 2903

使用freesurfer和3Dslicer进行脑区分割和电极定点(详细版)

1、安装好matlab和freesurfer2、在目标位置创建文件夹3、开放权限4、将需要计算的nii文件放入文件夹。

zQIANYUN的博客 5631

TestNG设置输出测试报告的内容级别和设置测试用例按顺序执行

转自:http://blog.youkuaiyun.com/bwgang/article/details/7864958   [html] view plaincopy   <?xml version="1.0" encoding="UTF-8"?>   <!DOCTYPE suite SYSTEM "http://testng.org/testng-1....

keke_Xin的专栏 872

SpringBoot使用mybatis-plus的自动代码生成器

一.SpringBoot使用mybatis-plus+自动代码生成 使用mybatis-plus可以自动帮我们生成通用的 controller,service,dao,mapper 二.加入依赖 <!-- MP 核心库 --> <dependency> <groupId>com.baomidou</groupId> <artif...

农民娃儿的博客 2263

Python调用Google Trends官方数据接口实战指南

Google Trends作为全球最权威的搜索热度分析工具,其数据本质是公开、结构化、可编程访问的时序指标,而非需爬取的网页内容。其底层基于标准HTTP协议与JSON API交互,核心原理在于复现用户浏览器行为——通过/explore接口获取token,再凭token请求/widgetdata/multiline等端点获取归一化(0-100)时间序列数据。该技术路径规避了Selenium渲染依赖与非官方库的脆弱性,具备高稳定性、易调试、可监控等工程优势,广泛应用于竞品监测、内容选题验证、地域营销策略制定等业

weixin_29789925的博客 421

Java自动化测试之TestNG生成测试报告

java自动化测试生成testng测试报告

Leoon123的博客 6097

RV1106的ISP配置实战:MIPI与LVDS接口的硬件连接与设备树优化

本文详细解析了RV1106芯片的ISP配置实战,重点对比了MIPI CSI-2与LVDS两种主流接口的硬件连接方案与数据流差异。通过手把手的设备树代码示例,深入讲解了单路MIPI与双路LVDS摄像头的配置要点、关键属性设置及常见避坑指南,并提供了从驱动加载检查到Media Controller工具使用的系统化调试方法,帮助开发者快速打通图像采集与处理全链路。

terraform7cloud的博客 471

TestNG执行测试用例的方法

2. 如果想要进一步的对测试套集里的测试用例执行顺序进行限定和设置的话,那么可以用到TestNG的另一个属性preserve-order, 当preserve-order="true", 表示测试用例按照XML文件里所列的顺序进行顺序执行,当preserve-order="false"时,表示测试用例不会按照XML文件里的顺序进行顺序执行,即会有乱序执行。1. TestNG里有suite的概念,即可以把多个测试用例放在一个***testng.xml的XML文件中执行,里面有定义好的要测的测试用例。

2401_88752684的博客 823

海康H304NAS 刷机飞牛

本文旨在分享如何将闲置的海康威视H304 NAS刷入飞牛NAS系统,并利用iStoreOS作为安装媒介。之前因为使用极空间NAS,这台H304闲置已久。最近尝试了飞牛NAS,在虚拟机上安装后挂载极空间的电影资源,体验不错,于是决定重新折腾这台H304。我个人喜欢尝试新系统,之前经常更新H304的固件,但设备总在使用一两年后出现故障,需要联系技术清理日志才能恢复。最后一次设备“变砖”后,连技术人员也联系不上了,自己尝试修复未果,设备就此闲置两三年。

u012985257的博客 2748

E-SMILES:化学信息学中的分子表示革命与应用

分子表示是化学信息学和计算化学的基础技术,其核心是将复杂的分子结构转化为计算机可处理的数字化形式。传统SMILES格式虽然广泛应用,但在处理复杂化学体系时存在局限性。Extended SMILES(E-SMILES)通过扩展语法规则,支持立体化学、配位键等特殊结构的精确描述,显著提升了分子表示的准确性和适用范围。在药物研发中,E-SMILES能准确描述蛋白质-配体相互作用和共价抑制剂;在材料科学领域,它支持纳米材料和超分子体系的多尺度建模。结合机器学习等前沿技术,E-SMILES正在推动化学信息处理效率的革

weixin_28683165的博客 279

TestNG测试框架之测试用例的执行顺序分析

既然是讨论执行顺序问题,那么用例肯定是批量执行的,批量执行的方法有mvn test、直接运行testng.xml文件,其中直接运行testng.xml文件的效果与pom文件中配置执行testng.xml效果是一样,所以本次只讨论mvn test 批量运行方式。 一、用例准备 1、 测试用例 编写一些测试用例,单纯为了测试,内容只进行输入,没有任何逻辑。 public class FirstTest { @Test public void testFirst(){ .

专注自动化、性能测试、测试架构学习交流 2381

Spatial-ORMLLM: Improve Spatial Relation Understanding in the Operating Room with Multimodal Larg...

手术室(OR)中的精准空间建模是众多临床任务的基础,可为术中感知、风险规避及手术决策提供支持。现有方法虽利用大规模多模态数据集进行 latent 空间对齐,以隐式学习空间关系,但却忽视了多模态大型语言模型(MLLM)的3D能力。然而,这种方法存在两个问题:1)手术室通常缺乏多台视频和音频传感器,多模态3D数据难以获取;2)仅依赖易获取的2D数据训练,无法捕捉复杂场景中的细粒度细节。为解决这一问题,我们提出——首个针对手术室3D空间推理的大型视觉语言模型。

UnknownBody_2的博客 592

TestNG如何编排测试用例,第3种方式最实用

testng 编排测试用例

雨水的早晨的博客 1031

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: TestNG测试套件
下一篇: 在Eclipse中安装TestNG
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值