testng-ex

extension the testng

License

License

Categories

Categories

TestNG Unit Testing
GroupId

GroupId

com.github.phoenix-young
ArtifactId

ArtifactId

testng-ex
Last Version

Last Version

0.4.7
Release Date

Release Date

Type

Type

jar
Description

Description

testng-ex
extension the testng
Project URL

Project URL

https://github.com/phoenix-young/ApiTest
Source Code Management

Source Code Management

https://github.com/phoenix-young/ApiTest

Download testng-ex

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.phoenix-young/testng-ex/ -->
<dependency>
    <groupId>com.github.phoenix-young</groupId>
    <artifactId>testng-ex</artifactId>
    <version>0.4.7</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.phoenix-young/testng-ex/
implementation 'com.github.phoenix-young:testng-ex:0.4.7'
// https://jarcasting.com/artifacts/com.github.phoenix-young/testng-ex/
implementation ("com.github.phoenix-young:testng-ex:0.4.7")
'com.github.phoenix-young:testng-ex:jar:0.4.7'
<dependency org="com.github.phoenix-young" name="testng-ex" rev="0.4.7">
  <artifact name="testng-ex" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.phoenix-young', module='testng-ex', version='0.4.7')
)
libraryDependencies += "com.github.phoenix-young" % "testng-ex" % "0.4.7"
[com.github.phoenix-young/testng-ex "0.4.7"]

Dependencies

compile (16)

Group / Artifact Type Version
cglib : cglib jar 3.2.5
org.testng : testng jar 6.13.1
commons-logging : commons-logging jar 1.1.3
org.springframework : spring-core jar 4.3.9.RELEASE
org.springframework : spring-context jar 4.3.9.RELEASE
org.springframework : spring-beans jar 4.3.9.RELEASE
org.springframework : spring-jdbc jar 4.3.9.RELEASE
mysql : mysql-connector-java jar 5.1.16
org.mybatis : mybatis jar 3.4.4
org.mybatis : mybatis-spring jar 1.3.1
com.google.code.gson : gson jar 2.8.0
commons-lang : commons-lang jar 2.5
org.apache.logging.log4j : log4j-api jar 2.8.2
org.apache.logging.log4j : log4j-core jar 2.8.2
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.2.30
org.jetbrains.kotlin : kotlin-reflect jar 1.2.30

test (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-test jar 1.2.30

Project Modules

There are no modules declared in this project.

TestNg-Ex

  • Introduction
    TestNg-Ex is an extension for testng, mainly force on data provider

  • Dependency
    JDK1.8

  • Configuration

    1. MAVEN dependency
    <dependency>
        <groupId>com.github.phoenix-young</groupId>
        <artifactId>testng-ex</artifactId>
        <version>0.4.7</version>
    </dependency>
    1. IDE Config(I use IDEA)
      Add listener com.apitest.nglisteners.ApiTestListener under Run->Edit Configurations->Defaults->TestNg->Listeners
  • Basic

    1. Values Data Provider
    package com.apitest.sample;
    import com.apitest.dataProvider.Value;
    import org.testng.annotations.Test;
    
    public class ValueProviderTest {
    
        @Test
        public void intValue(@Value(ints = {1,2,3}) int value){
    
        }
    
        @Test void stringValue(@Value(strings = {"T1","T2","T3"})String value){
        
        }
    }
    
    1. Enum Data Provider
    public enum Company {
        Microsoft,
        Sony,
        Nintendo;
    }
    
    public enum Console {
        XBOXONE(Company.Microsoft,2000),
        XBOX360(Company.Microsoft,1500),
        SWITCH(Company.Nintendo,2300),
        PS4(Company.Sony,1700),
        PS3(Company.Sony,1300),
        WII(Company.Nintendo,800),
        WIIU(Company.Nintendo,1300);
    
        private Company company;
        private int price;
    
        Console(Company company,int price){
            this.company = company;
            this.price = price;
        }
    
        public Company getCompany() {
            return company;
        }
    
        public int getPrice() {
            return price;
        }
    }
    
    @Test
    public void enumInjectTest(Console console){
    
    }
    1. Function Data Provider

      • �inner function
      public class InnerFunctionTest {
      
          @Test
          public void innerFuntion(@Func(name = "getValues") String value){
      
          }
      
          public List<String> getValues(){
              return Arrays.asList("A","B","C");
          }
      
      }
      • static function
      public class StaticFunctionProvider{
      
          public static List<Integer> getValues(){
              return Arrays.asList(1,2,3);
          }
      
      }
      public class StaticFunctionTest {
      
          @Test
          public void staticFunction(@Func(name = "getValues",provider = StaticFunctionProvider.class) int value){
      
          }
      }
      • outer instance function(Class need default parameterless construction)
      public class OuterFunctionProvider {
          public List<Console> getConsoles(){
              return Arrays.asList(Console.values()).stream().filter(c->c.getCompany() == Company.Microsoft).collect(Collectors.toList());
          }
      }
      public class OuterFunctionTest {
          @Test
          public void outerFunction(@Func(name = "getConsoles",provider = OuterFunctionProvider.class) Console console){
      
          }
      }
      • Function with parameters(only String parameter support)
      public class FunctionWithParameterTest {
      
          @Test
          public void functionWithParameter(@Func(name = "getData",args = {"5","2"})int value){
      
          }
      
          public List<Integer> getData(String p1,String p2){
              int value = Integer.parseInt(p1);
              List<Integer> list = new ArrayList<>();
              for(int i =0;i<value;i++){
                  list.add(i);
              }
              return list;
          }
      }
    2. CSV Data Provider

      • csv Data ( CSV file should put in with the test class in the same package )

        id name age
        1 test1 22
        2 test2 18
        3 test3 19
      • Create a POJO

      public class Student implements Serializable {
      
          private int id;
      
          private String name;
      
          private int age;
      
          public int getId() {
              return id;
          }
      
          public void setId(int id) {
              this.id = id;
          }
      
          public String getName() {
              return name;
          }
      
          public void setName(String name) {
              this.name = name;
          }
      
          public int getAge() {
              return age;
          }
      
          public void setAge(int age) {
              this.age = age;
          }
      }
      public class csvDataProvider {
      
          /**
           * if no file specific, the extension will find csv using the same name of class
           * and here will look for file csvDataProvider.csv
           */
          @Test
          public void csvData(@Csv Student student){
          
          }
      
      
          @Test
          public void csvDataWithFileName(@Csv(files = "csvDataProvider.csv") Student student){
          
          }
      
          /**
           * Using Map instead of POJO
           */
          @Test
          public void csvDataUsingMap(@Csv Map<String,String> student){
          
          }
      }
  • Combination(�if the parameter is POJO,it should implement the interface Serializable)

public class CombinationProviderTest {

    /**
     * 7 console type with 3 company type
     * the result will be 7 * 3
     */
    @Test
    public void enumCombinationTest(Console console, Company company){

    }

    /**
     * 7 console type ,3 integer value ,2 string value
     * the result will be 7 * 3 * 2 = 42
     */
    @Test
    public void otherCombinationTest(Console console, @Value(ints = {1,2,3}) int value,@Value(strings = {"a","b"}) String str){
        
    }

}
  • Filter
package com.apitest.sample.combination;

import com.apitest.annotations.Filter;
import com.apitest.testModels.Company;
import com.apitest.testModels.Console;
import org.testng.annotations.Test;

public class CombinationWithFilterTest {


    /**
     * 7 console type,3 company type
     * filter only need company type as Microsoft
     * the result will be 7 * 1 = 7
     */
    @Test
    @Filter(method = "filterCompany")
    public void filterTest(Console console, Company company){

    }

    /**
     * Attention
     * 1. Filter method should has same parameter type with the test method
     * 2. Return type of filter method must be boolean
     */
    public boolean filterCompany(Console console,Company company){
        return company == Company.Microsoft;
    }


    public boolean filterCompany2(Console console,Company company){
        return console == Console.PS4 || console == Console.SWITCH;
    }


    /**
     * Mutiple filter support
     */
    @Test
    @Filter(method = "filterCompany")
    @Filter(method = "filterCompany2")
    public void filterTest2(Console console,Company company){
        
    }

}

Versions

Version
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3