Giter Site home page Giter Site logo

testng-alwaysrun's Introduction

testng-alwaysrun

A Listener and AnnotationTransformer which will find TestNG configuration methods (@AfterX and @BeforeX) and change their alwaysRun fields to True.

If at least one test class in the project is marked with the Listener class, then all relevant test suite classes will be processed in this way.

@Listeners(AlwaysRunAnnotationTestListener.class)
public class MyTestClass() {
  ...
}

An alternative annotation transformer is also provided, which can be used in your testng.xml to add this functionality at a per-suite level.

<suite>
  <listeners>
    <listener class-name="com.github.ajshepley.AlwaysRunAnnotationTransformer" />
  </listeners>
</suite>

If the field cannot be set, reflective exceptions will be logged but the test runner will continue.


Rationale

The configuration methods provided by TestNG are, by default, not guaranteed to run depending on various factors.

There can be good reasons for this, but in JUnit and other test frameworks, the opposite behaviour is expected by default.

TestNG provides the alwaysRun field on these annotations to allow you to adjust this behaviour. It defaults to false.

Sometimes this cleanup or setup code is critical to the test or test resources, and so it is useful for an organization to have a way to ensure that these calls always run and do so by default.

Thus it is useful to have a Listener and Annotation Transformer to adjust this behaviour.


Building and Dependencies

The included Gradle4 wrappers can be used to build the project (./gradlew or .\gradlew.bat).

Java 8 is required. See Warning below for more information.

This repo is meant more as an illustration of how to work around this TestNG behaviour than to serve directly as a dependency.

However, a classes dependency jar can be created using the jar task. This is included as a default build task.

The TestNG version can be tweaked in the ext block in build.gradle.

Warning

When building, the following warning may appear:

WARNING: An illegal reflective access operation has occurred
...
WARNING: All illegal access operations will be denied in a future release

This occurs because the methodology used in changing the annotation field uses cross-module reflective accessibility changes, and therefore will not function correctly in Java 9 and later.

You can try using the flag –illegal-access=permit to force it to work.


Project Setup

A .idea/ directory is included, which has a variation of Google's java style called "GoogleStyle-Chop".

You can use that directory to instantiate the project with IntelliJ IDEA, or you can import the Gradle project in your IDE.

testng-alwaysrun's People

Contributors

ajshepley avatar

Watchers

 avatar  avatar

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.