In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about TestNg automation test case design and management of general strategies, the editor feels very practical, so share with you to learn, I hope you can learn something after reading this article, say no more, follow the editor to have a look.
General Strategy of use case Design for Automated testing
When we do automated testing, we need to manage the use case, and the more common solution is (take java as an example)
One project corresponds to one product.
A package corresponds to a module in the product.
A scene in the corresponding module of a class
A test method corresponds to a test point in a scenario.
Finally, the class to be executed by the organization is defined through suite.
As shown in the following figure, TestNGDemo is defined as a product, package com.my.case1, com.my.case2, and com.my.case3 represent three modules in the product, while six classes, such as MyCase1 and MyCase2, represent six test scenarios.
We can design specific test points in the class, as shown in the following figure, the methods f9 and f10 in class MyCase5 represent two test points (based on Testng)
Use case organization in TestNg
Testng manages test cases through configuration files, as follows:
A suite can define the test to be executed, and can include multiple test
Package and class to be executed can be defined in a test (package and class can be defined at the same time, the two are juxtaposed)
A class can set the method to be executed, organized as follows:
Two test are defined in Suite: Simpletest and advancedtest
Package:com.my.case1 and class: com.my.case2.MyCase4 to be executed are defined in Simpletest
Method f7 to be executed and method f8 not to be executed are defined in the class MyCase4
The class:com.my to be executed is defined in advancedtest. Case3.MyCase5
The running results are as follows:
Class MyCase1 under the com.my.case1 package and all methods in class MyCase2 are running, F1, f2, f3, and f4
Only method f7 is run in class MyCase4
All the methods in the class MyCase5 are running, f9 and f10.
Application of group in TestNG basic use of Group
TestNG can perform complex test method grouping to classify test cases. Can be identified by @ Test (groups = {"group 1", "group 2"})
A grouping can act on a specific class and method, indicating that all methods in the class belong to the grouping, while acting on methods means that only the method belongs to the grouping.
The specific code is as follows:
The MyCase1 class has the smoketest tag @ Test (groups = {"smoketest"}) public class MyCase1 {@ Test public void F1 () {System.out.println ("MyCase1 F1"); assertEquals ("a", "b");} @ Test public void f2 () {System.out.println ("MyCase1 f2"); assertEquals ("a", "a") }} only f3 methods of the MyCase2 class have smoketest tags public class MyCase2 {@ Test (groups = {"smoketest"}) public void f3 () {System.out.println ("MyCase2 f3"); assertEquals ("a", "b");} @ Test public void f4 () {System.out.println ("MyCase2 f4"); assertEquals ("a", "a") }} MyCase3 class has the performancetest tag @ Test (groups = {"performancetest"}) public class MyCase3 {@ Test public void f5 () {System.out.println ("MyCase3 f5"); assertEquals ("a", "b");} @ Test public void f6 () {System.out.println ("MyCase3 f6"); assertEquals ("a", "a") }} only f8 methods of the MyCase4 class have performancetest tags public class MyCase4 {@ Test public void f7 () {System.out.println ("MyCase4 f7"); assertEquals ("a", "b");} @ Test (groups = {"performancetest"}) public void f8 () {System.out.println ("MyCase4 f8"); assertEquals ("a", "a") }} MyCase5 class has securitytest and performancetest tags public class MyCase5 {@ Test (groups = {"securitytest", "performancetest"}) public void f9 () {System.out.println ("MyCase5 f9"); assertEquals ("a", "b");} @ Test public void f10 () {System.out.println ("MyCase5 f10"); assertEquals ("a", "a") }} MyCase6 class has the securitytest tag @ Test (groups = {"securitytest"}) public class MyCase6 {@ Test public void f11 () {System.out.println ("MyCase6 f11"); assertEquals ("a", "b");} @ Test public void f12 () {System.out.println ("MyCase6 f12"); assertEquals ("a", "a");}}
Set up the configuration file as follows:
The define tag section defines the required group classification, which can be omitted, but it is personally recommended to retain it. Using define, you can clearly see the existing group structure.
The run tag contains the group information that needs to be run. We can set the grouping that needs to be executed and the grouping that does not need to be executed through include and exclude. The method is very simple, as shown below:
In the figure above, the use case that runs the securitytest group identity is set up through include.
The running result is as follows: you can see that all the use cases under the securitytest tag are running
@ BeforeGroups and @ AfterGroups applications
The @ BeforeGroups annotated method will be executed once before any test method in this group is executed and can be used to perform initialization operations. A similar @ AfterGroups annotated method will be executed after any test method in this group is executed and can be used to close resources. @ Test (groups = {"smoketest"})
Public class MyCase1 {@ BeforeGroups (groups = {"smoketest"}) public void setup () {System.out.println ("smoketest setup");} @ AfterGroups (groups = {"smoketest"}) public void teardown () {System.out.println ("smoketest teardown");} @ Test public void F1 () {System.out.println ("MyCase1 F1"); assertEquals ("a", "b") @ Test public void f2 () {System.out.println ("MyCase1 f2"); assertEquals ("a", "a");}}
The code is executed as follows: you can see @ BeforeGroups and @ AfterGroups in the group smoketest
It is executed before and after the operation of
These are the general strategies for automating test case design and management in TestNg. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.