Git Product home page Git Product logo

test-data-supplier's Introduction

Test Data Supplier

Build Status Quality Gate Code Coverage Vulnerabilities Bugs Code Smells Technical Debt Security Rating Maintainability Rating Reliability Rating Maven Central GitHub license Twitter

Table of Contents

Description

test-data-supplier.mp4

This repository contains TestNG DataProvider wrapper (the latest version is based on TestNG 7.7.1) which helps to supply test data in a more flexible way.

Common DataProvider forces using quite old and ugly syntax which expects one of the following types to be returned from DP method's body:

  • Object[][]
  • Iterator<Object[]>

That's weird as developers tend to use Stream and Collection API for data manipulation in the modern Java world.

Just imagine if you could use the following syntax to supply some filtered and sorted data into test method's signature:

@DataSupplier
public Stream<User> getData() {
    return Stream
        .of(
            new User("Max", "password2"),
            new User("Black Fox", "password3"),
            new User("Mark", "password1")
        )
        .filter(u -> !u.getName().contains("Fox"))
        .sorted(comparing(User::getPassword));
}
    
@Test(dataProvider = "getData")
public void shouldSupplyStreamData(final User user) {
    // ...
}

Much better and flexible than two-dimensional arrays or iterators, isn't it?

And what if we don't want to iterate the same test N times depending on collection size? What if we want to inject it into test's signature like the following?

@DataSupplier(transpose = true)
public List<User> getTransposedData() {
    return StreamEx
        .of(
            new User("username1", "password1"),
            new User("username2", "password2")
        )
        .toList();
}
        
@Test(dataProvider = "getTransposedData")
public void shouldSupplyExtractedListData(final List<User> users) {
    // ...
}

Or if you want to extract the values of your collection and inject into test's signature, you can combine transpose with a flatMap:

@DataSupplier(transpose = true, flatMap = true)
public Set<User> getExtractedData() {
    return StreamEx.of("product1", "product2", "product1").toSet();
}
        
@Test(dataProvider = "getExtractedData")
public void shouldSupplyExtractedListData(final String... products) {
    // ...
}

Java-like flatMap operation can be applied even to more complicated structures like Map to extract values for each row:

@DataSupplier(flatMap = true)
public Map<Integer, String> getInternallyExtractedMapData() {
    return EntryStream.of(asList("user3", "user4")).toMap();
}
    
@Test(dataProvider = "getInternallyExtractedMapData")
public void supplyInternallyExtractedMapData(final Integer key, final String value) {
    // not implemented
}

Go top ☝️

Supported flags

  • name: sets a custom name for DataSupplier (method name is used by default)
  • transpose: translates data column into a single row
  • flatMap: behaves pretty much like a native Java Stream operation
  • runInParallel: executes each data-driven test in parallel rather than sequentially
  • indices: filters the underlying collection by given indices
  • propagateTestFailure: fails the test in case of DataSupplier failure (skips by default)

Go top ☝️

Supported return types

  • Collection
  • Map
  • Entry
  • Object[]
  • double[]
  • int[]
  • long[]
  • Stream / StreamEx
  • Tuple
  • A single Object of any common or custom type

Go top ☝️

Usage

Gradle - Java < 9

Add the following configuration into build.gradle:

repositories {
    mavenCentral()
}
    
configurations {
    agent
}

sourceCompatibility = JavaVersion.VERSION_1_8

ext {
    aspectjVersion = '1.9.7'
}

[compileJava, compileTestJava]*.options*.compilerArgs = ['-parameters']
    
dependencies {
    agent "org.aspectj:aspectjweaver:${aspectjVersion}"
    implementation(
            "org.aspectj:aspectjweaver:${aspectjVersion}",
            'org.testng:testng:6.14.3',
            'io.github.sskorol:test-data-supplier:1.7.0'
    )
}
    
test {
    doFirst {
        jvmArgs("-javaagent:${configurations.agent.singleFile}")
    }
    
    useTestNG()
}

Check a separate project with usage examples.

Go top ☝️

Maven - Java < 9

Add the following configuration into pom.xml:

<properties>
    <aspectj.version>1.9.7</aspectj.version>
    <java.version>1.8</java.version>
    <compiler.plugin.version>3.8.0</compiler.plugin.version>
    <surefire.plugin.version>2.20.1</surefire.plugin.version>
</properties>
    
<dependencies>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>${aspectj.version}</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.3</version>
    </dependency>
    <dependency>
        <groupId>io.github.sskorol</groupId>
        <artifactId>test-data-supplier</artifactId>
        <version>1.7.0</version>
    </dependency>
</dependencies>
    
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${compiler.plugin.version}</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <compilerArgs>
                    <arg>-parameters</arg>
                </compilerArgs>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${surefire.plugin.version}</version>
            <configuration>
                <argLine>
                    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                </argLine>
            </configuration>
        </plugin>
    </plugins>
</build>

Check a separate project with usage examples.

Go top ☝️

Gradle - Java 11-16 w/o modules

plugins {
    id 'java'
}
    
sourceCompatibility = JavaVersion.VERSION_11
    
repositories {
    mavenCentral()
}
    
configurations {
    agent
}

ext {
    aspectjVersion = '1.9.7'
}

[compileJava, compileTestJava]*.options*.compilerArgs = ['-parameters']
    
dependencies {
    agent "org.aspectj:aspectjweaver:${aspetjVersion}"
    implementation(
            "org.aspectj:aspectjweaver:${aspectjVersion}",
            'org.testng:testng:7.4.0',
            'io.github.sskorol:test-data-supplier:1.9.7'
    )
}
    
test {
    doFirst {
        jvmArgs("-javaagent:${configurations.agent.singleFile}")
    }
    
    useTestNG()
}

Go top ☝️

Gradle - Java 11-16 w/ modules

It's a bit tricky in terms of building and testing modular applications:

plugins {
    id 'java-library'
    id 'java'
}
    
ext {
    moduleName = 'your.module.name'
}
    
sourceCompatibility = JavaVersion.VERSION_11
    
repositories {
    mavenCentral()
}
    
configurations {
    agent
}

ext {
    aspectjVersion = '1.9.7'
}
    
dependencies {
    agent "org.aspectj:aspectjweaver:${aspectjVersion}"
    implementation(
            "org.aspectj:aspectjweaver:${aspectjVersion}",
            'org.testng:testng:7.4.0',
            'io.github.sskorol:test-data-supplier:1.9.7'
    )
}
    
compileJava {
    inputs.property("moduleName", moduleName)
    doFirst {
        options.compilerArgs = [
                '--module-path', classpath.asPath
        ]
        classpath = files()
    }
}
   
compileTestJava {
    inputs.property("moduleName", moduleName)
    doFirst {
        options.compilerArgs = [
                '--module-path', classpath.asPath,
                '--patch-module', "$moduleName=" + files(sourceSets.test.java.srcDirs).asPath,
        ]
        classpath = files()
    }
}
   
test {
    useTestNG()
   
    inputs.property("moduleName", moduleName)
    doFirst {
        jvmArgs = [
                "-javaagent:${configurations.agent.singleFile}",
                '--module-path', classpath.asPath,
                '--add-modules', 'ALL-MODULE-PATH',
                '--add-opens', 'your.module.name/test.package.path=org.testng',
                '--add-opens', 'your.module.name/test.package.path=org.jooq.joor',
                '--patch-module', "$moduleName=" + files(sourceSets.test.java.outputDir).asPath
        ]
        classpath = files()
    }
}

Your module-info.java may look like the following:

module your.module.name {
    requires io.github.sskorol.testdatasupplier;
    requires org.testng;
   
    // Optional
    provides io.github.sskorol.core.IAnnotationTransformerInterceptor
        with path.to.transformer.ImplementationClass;
   
    provides io.github.sskorol.core.DataSupplierInterceptor
        with path.to.interceptor.ImplementationClass;
}

Go top ☝️

Gradle - Java 17+ w/o modules

Note that test-data-supplier:2.0.0+ has been compiled with java 17. It means you must use the same language level in your build file.

plugins {
    id 'java'
}
    
sourceCompatibility = JavaVersion.VERSION_17
    
repositories {
    mavenCentral()
}
    
configurations {
    agent
}

ext {
    aspectjVersion = '1.9.19'
}

[compileJava, compileTestJava]*.options*.compilerArgs = ['-parameters']
    
dependencies {
    agent "org.aspectj:aspectjweaver:${aspectjVersion}"
    implementation(
            "org.aspectj:aspectjweaver:${aspectjVersion}",
            'org.testng:testng:7.8.0',
            'io.github.sskorol:test-data-supplier:2.3.0'
    )
}
    
test {
    doFirst {
        jvmArgs(
            "-javaagent:${configurations.agent.singleFile}",
            '--add-opens', 'java.base/java.lang=ALL-UNNAMED'
        )
    }
    
    useTestNG()
}

Go top ☝️

Maven - Java 17+ w/o modules

<properties>
    <aspectj.version>1.9.19</aspectj.version>
    <java.version>17</java.version>
    <compiler.plugin.version>3.11.0</compiler.plugin.version>
    <surefire.plugin.version>3.0.0-M9</surefire.plugin.version>
</properties>
    
<dependencies>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>${aspectj.version}</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.8.0</version>
    </dependency>
    <dependency>
        <groupId>io.github.sskorol</groupId>
        <artifactId>test-data-supplier</artifactId>
        <version>2.3.0</version>
    </dependency>
</dependencies>
    
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${compiler.plugin.version}</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <compilerArgs>
                    <arg>-parameters</arg>
                </compilerArgs>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${surefire.plugin.version}</version>
            <configuration>
                <argLine>
                    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                </argLine>
            </configuration>
        </plugin>
    </plugins>
</build>

Go top ☝️

API

Instead of a common DataProvider annotation use the following:

@DataSupplier
public T getData() {
    //...
}

DataSupplier supports the following args: name, transpose, flatMap, runInParallel, indices and propagateTestFailure.

You can refer DataSupplier the same way as with TestNG DataProvider:

@Test(dataProvider = "getData")
public void supplyData(final T data) {
    // ...
}
    
// or
    
@Test(dataProviderClass = ExternalDataProvider.class, dataProvider = "getData")
public void supplyExternalData(final T data) {
    // ...
}

Check io.github.sskorol.testcases package for more examples.

Go top ☝️

JSON, CSV, YAML and XLSX processors

Test data supplier supports JSON, CSV, YML and XLSX data retrieval. Assuming you have the following resources:

username,password
"admin","admin"
"sskorol","password"
"guest","123"
[
  {
    "username": "admin",
    "password": "admin"
  },
  {
    "username": "sskorol",
    "password": "password"
  },
  {
    "username": "guest",
    "password": "123"
  }
]
---
 username: admin
 password: admin
---
 username: sskorol
 password: password
---
 username: guest
 password: '123'
USERNAME  PASSWORD
admin     admin
sskorol   password
guest     123

You can now map Java entities to these data sources using @Source annotation, which accepts either local file name or URL:

@Data
@Source(path = "users.csv")
public class User {
    @FieldName("username")
    private final String name;
    private final String password;
}
@Data
@Source(path = "users.json")
public class User {
    @SerializedName("username")
    private final String name;
    private final String password;
}
@Data
@NoArgsConstructor
@Source(path = "users.yml")
public class User {
    @JsonProperty("username")
    private final String name;
    private final String password;
}
@Data
@NoArgsConstructor
@Source(path = "users.xlsx")
@Sheet(name = "sheet_1")
public class User {
    @Column(name = "USERNAME")
    private String username;

    @Column(name = "PASSWORD")
    private String password;
}

In case if some Java field's name differs from its data source representation, you can assign a valid name via @FieldName for CSV, @SerializedName for JSON and @JsonProperty for YML data type.

Excel support is experimental. 2.0.0 version used ZeroCell library based on Apache POI to simplify corresponding files processing. Since 2.1.0, there's a custom implementation with similar approach, but minor improvements, e.g. there's no need to use column index anymore.

In terms of fields' mapping, you can use custom @Column annotation (don't confuse with ZeroCell Column). You should also make sure you provided a sheet name via corresponding @Sheet annotation. Otherwise, the first one will be used. In case if you have a similar structure on multiple sheets, you can use a repeatable @Sheets annotation. Dynamic sheets' specification is also possible via withAdditionalSources builder method (see examples below).

Similarly to ZeroCell, you can use either default or custom fields' converters. Here's a list of defaults:

  • BooleanConverter
  • DoubleConverter
  • IntegerConverter
  • LocalDateConverter
  • LocalDateTimeConverter
  • StringConverter

To use custom converter, you should specify its class via @Column annotation.

@Column(name = "Tags", converter = StringToListConverter.class)
private List<String> data;

And the actual implementation may look like the following:

public class StringToListIConverter extends DefaultConverter<List<String>> {
    @Override
    public List<String> convert(final String value) {
        return asList(value.split(","));
    }
}

Custom converters must extend DefaultConverter class. Also note that by default test-data-supplier uses an implicit conversion based on the field type. So you don't have to explicitly specify a converter if it's among the defaults.

Local data sources must be located in a classpath. You usually use resources folder for that.

Then, within @DataSupplier you can call a special TestDataReader builder to retrieve data from CSV, JSON, YML or XLSX data source. See javadocs to get more details.

@DataSupplier
public StreamEx<User> getUsers() {
    return use(CsvReader.class).withTarget(User.class).withSource("users.csv").read();
}
@DataSupplier
public StreamEx<User> getUsers() {
    return use(JsonReader.class).withTarget(User.class).withSource("http://users.json").read();
}
@DataSupplier
public StreamEx<User> getUsers() {
    return use(YamlReader.class).withTarget(User.class).read();
}
@DataSupplier
public StreamEx<User> getUsers() {
    return use(XlsxReader.class).withTarget(User.class).read();
}
@DataSupplier
public StreamEx<User> getUsers() {
    return use(XlsxReader.class).withTarget(User.class).withAdditionalSources("Sheet1", "Sheet2").read();
}

If you want to specify a custom source in runtime, you can remove @Source annotation and use withSource builder method instead. withAdditionalSources builder method is experimental and implemented for XlsxReader as a dynamic sheets provider.

Note that in case of a data reading error or any kind of exception thrown in a @DataSupplier body, the corresponding test will be skipped. That's a default TestNG behaviour. However, you can set propagateTestFailure flag (introduced in TestNG 7.6.0) to explicitly mark the test as failed.

Go top ☝️

DB support

Technically, there's no need to create an additional ORM wrapper to work with databases. But it's worth to show how to perform such integration.

Let's use ebean and Postgres as an example.

First, create an application-test.yaml with db connection details in your test resources' folder:

ebean:
  test:
    useDocker: false
    platform: postgres
    ddlMode: none
    dbName: your_db
    dbSchema: your_schema
    postgres:
      username: your_username
      password: your_password
      url: jdbc:postgresql://localhost:5432/your_db

Next, create a mapping with your DB table:

@MappedSuperclass
public class BaseEntity extends Model {
    @Id
    long id;
}

@Entity
@Table(name = "testing.users")
public class UserEntity extends BaseEntity {
    @NotNull
    public String email;

    @Column(name = "is_active")
    public boolean isActive;
}

Now, you can supply users to your test the following way:

@DataSupplier
public List<UserEntity> usersData() {
    return find(UserEntity.class)
        .where()
        .like("email", "%korol%@gmail.com")
        .and()
        .eq("is_active", true)
        .findList();
}

Go top ☝️

Factory

You can specify DataSupplier for Factory annotation as well as for common test methods.

@NoArgsConstructor
public class InternalFactoryTests {
    
    @DataSupplier
    public StreamEx getConstructorData() {
        return IntStreamEx.rangeClosed(1, 3).boxed();
    }
    
    @DataSupplier
    public String getTestData() {
        return "data";
    }
    
    @Factory(dataProvider = "getConstructorData", dataProviderClass = InternalFactoryTests.class)
    public InternalFactoryTests(final int index) {
        // not implemented
    }
    
    @Test(dataProvider = "getTestData")
    public void internalFactoryTest(final String data) {
        // not implemented
    }
}

Go top ☝️

Tracking meta-data

DataSupplierInterceptor interface allows tracking original DataProvider method calls for accessing additional meta-data. You can use the following snippet for getting required info:

public class DataSupplierInterceptorImpl implements DataSupplierInterceptor {
    
    private static final Map<ITestNGMethod, DataSupplierMetaData> META_DATA = new ConcurrentHashMap<>();
    
    @Override
    public void beforeDataPreparation(final ITestContext context, final ITestNGMethod method) {
    }
    
    @Override
    public void afterDataPreparation(final ITestContext context, final ITestNGMethod method) {
    }
    
    @Override
    public void onDataPreparation(final DataSupplierMetaData testMetaData) {
        META_DATA.putIfAbsent(testMetaData.getTestMethod(), testMetaData);
    }
    
    @Override
    public Collection<DataSupplierMetaData> getMetaData() {
        return META_DATA.values();
    }
}

This class should be then loaded via SPI mechanism. Just create META-INF/services folder in resources root, and add a new file io.github.sskorol.core.DataSupplierInterceptor with a full path to implementation class.

Go top ☝️

IAnnotationTransformer restriction

TestNG restricts users in a number of IAnnotationTransformer implementations. You may have not more than a single transformer within project's scope. As test-data-supplier uses this interface for its internal stuff, you won't be able to apply your own implementation.

In case if you still need to add a custom IAnnotationTransformer, you have to implement the following interface:

public class IAnnotationTransformerInterceptorImpl implements IAnnotationTransformerInterceptor {

    @Override
    public void transform(IFactoryAnnotation annotation, Method testMethod) {
    }

    @Override
    public void transform(IConfigurationAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
    }

    @Override
    public void transform(IDataProviderAnnotation annotation, Method method) {
    }

    @Override
    public void transform(IListenersAnnotation annotation, Class testClass) {
    }
}

It's just an SPI wrapper for common TestNG feature. Use the same technique as for DataSupplierInterceptor to include it into your project.

Note that in case if you want to manage DataProviderTransformer manually, you have to use a special spi-off distribution:

dependencies {
    implementation 'io.github.sskorol:test-data-supplier:2.3.0:spi-off'
}

Go top ☝️

IntelliJ IDEA support

Test Data Supplier also has an IntelliJ IDEA plugin. Just install test-data-supplier-plugin from the official JetBrains repository.

More information about its features can be found on the related GitHub page.

Go top ☝️

test-data-supplier's People

Contributors

dependabot[bot] avatar jmaeso avatar sskorol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

test-data-supplier's Issues

Add DS analysis on subclass level

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.4.1
TestNG 6.14.3
Build tool [email protected]
IDE [email protected]

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

See TestNG-1691

What is the actual behavior?

TestNG / DS ignores subclass level annotations.

What is the motivation / use case for changing the behavior?

See TestNG-1691

Other information

Most likely it requires additional libs involvement for subtypes scanning in runtime.

AspectJ reference is missing in README

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.7.0
TestNG 6.14.3
Build tool [email protected]
IDE [email protected]

Is the issue reproducible on a runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

The installation part of README must include aspectj reference, as it's required for all the service loaders that are handled by internal aspect implementation.

What is the actual behavior?

Missing aspectj in README leads to confusion, as users' SPIs are not being called.

What is the motivation / use case for changing the behavior?

Improve UX.

Revise data retrieval mechanism

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.6.5
TestNG 6.14.3
Build tool [email protected]
IDE [email protected]

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

Json, Yaml, Csv readers should be generic with an ability to specify a custom source type in runtime.

What is the actual behavior?

Readers are static. There's no way to specify custom source in runtime. Only via Source annotation.

What is the motivation / use case for changing the behavior?

Provide more flexible data reading mechanism.

Other information

Use a mix of Strategy and Builder pattern with an ability to set custom data source.

Downgrade to Gradle 4.5.1

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.5.0
TestNG 6.14.3
Build tool [email protected]
IDE [email protected]

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

User is able to release a new version.

What is the actual behavior?

Gradle throws caching exception while releasing.

What is the motivation / use case for changing the behavior?

Release a new version.

Other information

Downgrade Gradle to 4.5.1 version.

Add indices support

To make DataSupplier similar to DataProvider, it's required to implement indices[] arg support.
However, the same functionality could be achieved with streams.

Flattering collections and new return types

  • Add Map / Entry to the supported list of return types.
  • Sometimes it's required to perform a Java-like flatMap operation to extract collection values directly into test's signature.
    @DataSupplier(flatMap = true)
    public Map<Integer, String> getInternallyExtractedMapData() {
        return EntryStream.of(asList("user3", "user4")).toMap();
    }

    @DataSupplier(flatMap = true)
    public StreamEx getInternallyExtractedTupleData() {
        final List<String> list1 = asList("data1", "data2");
        final List<String> list2 = asList("data3", "data4");
        return IntStreamEx.range(0, Math.min(list1.size(), list2.size()))
                          .boxed()
                          .map(i -> Tuple.of(list1.get(i), list2.get(i)));
    }
  • Map should be transformed into list of Entry.

Update lib loading strategy to use SPI

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.4.5
TestNG 6.14.3
Build tool [email protected]
IDE [email protected]

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

User is not bothered with manual listener configuration.

What is the actual behavior?

Listener should be manually added to build file or xml.

What is the motivation / use case for changing the behavior?

Simplify installation flow.

Other information

Add org.testng.ITestNGListener SPI.

Update dependencies

Current dependencies are outdated. Apart from that, there were some TestNG issues fixed in the latest release. It's better to stay up to date.

Add Javadocs

All Javadocs are suppressed at moment. Need to add more details for existing API.

Update TestNG and other deps

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.4.0
TestNG 6.13.1
Build tool [email protected]
IDE [email protected]

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

Factories without explicitly set DP class, should implicitly set corresponding meta-data.

What is the actual behavior?

This feature is missing in TestNG 6.13.1. However, it's fixed in 6.14.2.

What is the motivation / use case for changing the behavior?

Add better Factory support.

Other information

See details: testng-team/testng#1647

Rft transformer

Split transformation logic between model and utility classes.

Java 9 support - illegal reflective access issue due to joor

While this issue is due to joor, I'd like to make it general for test-data-supplier to support JDK9.

Even if you won't be able to tackle it (for any reasons at all) I'd still want to thank you for creating this. :-)

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.7.0
TestNG 6.14.3
Build tool Maven 3.5
IDE [email protected]

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

No JDK9-related warnings.

What is the actual behavior?

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.joor.Reflect (file:/home/tammo/.m2/repository/org/jooq/joor-java-8/0.9.8/joor-java-8-0.9.8.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class)
WARNING: Please consider reporting this to the maintainers of org.joor.Reflect
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

What is the motivation / use case for changing the behavior?

JDK11 is just around the corner. JUnit 5 becomes an alternative for my beloved TestNG. :-) We can't have that!

Let me know if you'd like me to provide any details on, e.g., how I got the issue.

DataSupplier listener

Add a common DataSupplier interceptor for tracking before / after / around events.
Should be useful for collecting additional meta data and reporting tools integration.

Add basic CSV / JSON processing support

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.5.5
TestNG 6.14.3
Build tool [email protected]
IDE [email protected]

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

User should be able to read data from CSV / JSON files / urls into Java entities with minimal effort.

What is the actual behavior?

There're no native CSV / JSON processors.

What is the motivation / use case for changing the behavior?

Simplify users' scenarios for accessing data.

Other information

Create an utility class for getting CSV / JSON data via apache poi and gson libraries.

Add meta data injection support

Currently it's not possible to inject TestNG meta data (ITestContext / Method) into DataSupplier signature. Should be fixed on DataProviderTransformer level.

[FR] Add basic YAML processing support

Hi,

Aftrer #62 and #63 it would be grate to add YAML processing support

UseCase:

  1. List of objects is stored in the following YAML format:
---
 username: admin
 password: admin
---
 username: sskorol
 password: password
---
 username: guest
 password: '123'

The reason for usage "---" (start sign of YAML document) as object delimiter is complex objects with several nested structures.
Here is the Jakson parser exapmple:

fun getMapper(): ObjectMapper {
   return ObjectMapper(YAMLFactory()).registerModule(KotlinModule())
           .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
}
...
val result: ArrayList<T> = arrayListOf()
val data = YamlConverter().getMapper().readerFor(T::class.java)
                .readValues<T>(it)
while (data.hasNextValue()) {
            result.add(data.nextValue())
}

Downgrade Reflection package

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.9.3
TestNG 7.4.0
Build tool [email protected]
IDE [email protected]

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

Tests that use DS should fail due to DS internals.

What is the actual behavior?

ronmamo/reflections#277

What is the motivation / use case for changing the behavior?

Broken release.

Parameters in DataSupplier ?

I'm submitting

  • bug report
  • feature request
  • question

Content

Can we pass parameters in @DataSupplier ? sth like this

@DataSupplier
public Stream foo(String param1, int param2){
//return sth
}

@test(dataProvider = "foo", dataProviderParams = "stringA;5")
public void testFoo(Object bar) {
//test code here
}

Custom IAnnotationTransformer support

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.5.0
TestNG 6.14.3
Build tool [email protected]
IDE [email protected]

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

Users should be able to apply their own IAnnotationTransformer implementation.

What is the actual behavior?

Currently TestNG allows adding only a single implementation. As test-data-supplier uses transformer for its internal staff, a library prevents users from adding their own instances.

What is the motivation / use case for changing the behavior?

There shouldn't be any restrictions on test-data-supplier side.

Other information

Should be implemented via SPI.

Supplier doesn't initialize on Java 11

Updated jdk from 10 to 11.
Updated test-data-supplier to 1.8.2
Updated aspectj to 1.9.2

After launching testng test the follwing error occurs

AspectJ Internal Error: unable to add stackmap attributes. Unsupported class file major version 55
java.util.ServiceConfigurationError: org.testng.ITestNGListener: io.github.sskorol.core.DataProviderTransformer Unable to get public no-arg constructor
	at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:581)
	at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:672)
	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1232)
	at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1264)
	at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1299)
	at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1384)
	at org.testng.TestNG.addServiceLoaderListeners(TestNG.java:967)
	at org.testng.TestNG.initializeConfiguration(TestNG.java:906)
	at org.testng.TestNG.initializeEverything(TestNG.java:996)
	at org.testng.TestNG.run(TestNG.java:1009)
	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73)
	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: java.lang.VerifyError: Expecting a stackmap frame at branch target 45
Exception Details:
  Location:
    io/github/sskorol/core/DataProviderTransformer.supplyParallelData(Lorg/testng/ITestContext;Lorg/testng/ITestNGMethod;)Ljava/util/Iterator; @19: invokestatic
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0000000: 2b3a 042c 3a05 b200 9c2a 2a19 0419 05b8
    0000010: 008c 4eb8 0092 2db6 0096 2a2b 2cb6 0002
    0000020: b600 03b9 0004 0100 3a07 a700 0f3a 06b8
    0000030: 0092 2db6 0099 1906 bfb8 0092 2db6 0099
    0000040: 1907 b0                                
  Exception Handler Table:
    bci [19, 45] => handler: 45

	at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3138)
	at java.base/java.lang.Class.getConstructor0(Class.java:3343)
	at java.base/java.lang.Class.getConstructor(Class.java:2152)
	at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:659)
	at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:656)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:667)
	... 10 more

Fix Sonar violations

Some helper classes have issues with generics. Need to adjust signatures to pass the check.

Add ability to turn off SPI

Hi. We would like to have an ability to disable SPI in test-data-supplier.
Motivation: In our project we already have SPI with AnnotationTransformer. Adding test-data-supplier will break our tests because TestNG doesn't allow more than one annotation transformer enabled.

Possible solution: I spotted an interesting feature in allure-testng library. It allows to disable SPI by specifying 'spi-off' classifier in dependencies.
https://github.com/allure-framework/allure-java/blob/master/allure-testng/build.gradle.kts

It would be great if test-data-supplier has something similar. We love this library but due to SPI conflict we are forced to use old version without SPI: 1.4.0

Note: We understand that without SPI test-data-supplier's annotation transformer would require manual handling but we're ok with that.

@DataSupplier doesn't work with @Factory

public class SimpleTest{

    int i;

    @DataSupplier
    public Object[] ints(){
        return new Object[] {1, 2, 3};
    }

    public SimpleTest(){}

    @Factory(dataProvider = "ints")
    public SimpleTest(int i){
    this.i = i;
    }

    @Test
    public void simpleTest() {
        System.out.println("Simple Test Method " + i);
    }
}

Output:

Method public SimpleTest(int) requires a @DataProvider named : ints
	at org.testng.internal.Parameters.findDataProvider(Parameters.java:336)
	at org.testng.internal.Parameters.handleParameters(Parameters.java:498)
	at org.testng.internal.FactoryMethod.invoke(FactoryMethod.java:71)
	at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:158)
	at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:40)
	at org.testng.TestRunner.initMethods(TestRunner.java:401)
	at org.testng.TestRunner.init(TestRunner.java:250)
	at org.testng.TestRunner.init(TestRunner.java:220)
	at org.testng.TestRunner.<init>(TestRunner.java:161)
	at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:578)
	at org.testng.SuiteRunner.init(SuiteRunner.java:185)
	at org.testng.SuiteRunner.<init>(SuiteRunner.java:131)
	at org.testng.TestNG.createSuiteRunner(TestNG.java:1383)
	at org.testng.TestNG.createSuiteRunners(TestNG.java:1363)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1217)
	at org.testng.TestNG.runSuites(TestNG.java:1144)
	at org.testng.TestNG.run(TestNG.java:1115)
	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)

If we change @DataSupplier to @dataProvider everything works fine

TestNG 7.2.0 is missing as dependency for data supplier

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.9.2
TestNG 7.4.0
Build tool [email protected]

Is the issue reproducible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

To compile project.

What is the actual behavior?

At the moment test-data-supplier is depending on testNG 7.2.0 which is missing from mvn repository: https://mvnrepository.com/artifact/org.testng/testng Maybe to upgrade dependencies for test-data-supplier for testNG from 7.2.0 to 7.4.0.

test execution fails in case @Test annotation is assigned on class level

Hi,

test-data-supplier:1.2.0
gradle 4.2, kotlin 1.1.51, testng 6.11

build.gradle

tasks.withType(Test) {
    systemProperties = System.properties
    useTestNG {
        listeners << 'io.github.sskorol.core.DataProviderTransformer'
    }
    dependsOn prepareTestData
    testLogging.showStandardStreams = true
    outputs.upToDateWhen { false }
}

code:

@Test <<<<
class AddCustomer : BaseTest() {
    @DataSupplier
    fun addCustomersTestData(): List<CustomerInfo?> {
        return YamlConverter().fromYaml<CustomerInfo>("/testData/customer/requestData/addCustomers.yml")
                .map { it.addRandomPartToName() }
    }
    @Test(dataProvider = "addCustomersTestData")
    fun addCustomer(custInfoRequest: CustomerInfo) {
        val customerInfoResponse =
                RequestBuilder("Customer", "add_customer")
                        .sendPost(sessionID, custInfoRequest)
                        .extractBody<AddUpdateCustomerResponse>()
        Assertions.assertThat(customerInfoResponse.iCustomer).isPositive();
    }
}

STR:

  1. Run gradle test
Exception
org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 1.
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:63)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
	at com.sun.proxy.$Proxy1.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:119)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
	at io.github.sskorol.core.DataProviderTransformer.transform(DataProviderTransformer.java:36)
	at org.testng.internal.annotations.JDK15AnnotationFinder.transform(JDK15AnnotationFinder.java:155)
	at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:231)
	at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:204)
	at org.testng.TestNG.createCommandLineSuitesForClasses(TestNG.java:575)
	at org.testng.TestNG.initializeCommandLineSuites(TestNG.java:878)
	at org.testng.TestNG.run(TestNG.java:1104)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:129)
	at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:88)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
	... 25 more

Please check.Thank you.

Fix potential crash related to Reflections API update

Latest Reflections API causes runtime failure that is visible only while real lib usage. It should be downgraded.

Apart from that, it might be useful to provide TestNGMethod structure to the DataSupplierMetaData.

Changelog plugin seems abandoned. So it should be removed as well.

Rft: optimize code and migrate to Sonar

I'm submitting

  • bug report
  • feature request

Environment

Test Data Supplier 1.6.0
TestNG 6.14.3
Build tool [email protected]
IDE [email protected]

Is the issue reproductible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

What is the expected behavior?

All violations are fixed.

What is the actual behavior?

There're some code points which require optimization and decomposition.

What is the motivation / use case for changing the behavior?

Clean code.

Other information

Replace gradle quality plugin with Sonar Cloud.
Fix all the potential violations.

Migrate to TestNG 7.0.0

I'm submitting

  • bug report
  • feature request

Other information

Update outdated dependencies to provide a better Java 11 integration. Migrate to TestNG 7.0.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.