Giter Site home page Giter Site logo

sangrahah's Introduction

Sangrahah (means Collection).

This library is an answer to a TestNG defect.

Sangrahah lets you define a suite via a class using annotations as a means to creating an aggregation for execution.

Its similar to what already exists in JUnit.

Instead of creating a TestNG suite via an xml file, Sangrahah lets you define a suite file via a bunch of annotations.

Pre-requisites:

  • JDK8
  • TestNG 7.1.0 (or) higher.

To consume this library add the below as a maven dependency:

<dependency>
  <groupId>com.rationaleemotions</groupId>
  <artifactId>sangrahah</artifactId>
  <version>1.0.0</version>
</dependency>

Some examples are as below:

A simple example to start with

@XmlSuite(name = "Example_Suite",
    testClasses = {
        SampleTestCase.class,
        SampleTestCase2.class
    }
)
public class SuiteClass {
}

That's it. This class now doubles up as a full fledged TestNG suite xml. This class be directly executed via the surefire plugin (by configuring surefire plugin to pick up this class without a suite xml file)

An example of a suite file with detained class definitions.

import com.rationaleemotions.annotations.XmlSuite;
import com.rationaleemotions.annotations.internal.XmlClass;
import com.rationaleemotions.annotations.internal.XmlMethod;
import com.rationaleemotions.annotations.internal.XmlParameter;

@XmlSuite(name = "Example_Suite",
    classDefinitions = {
        @XmlClass(classToRun = SampleTestCase.class),
        @XmlClass(classToRun = SampleTestCase3.class,
            methods = {
                @XmlMethod(include = "anotherTestMethod",
                    parameters = {
                        @XmlParameter(name = "flag", value = "false")
                    }
                )
            }
        )
    }
)
public class SuiteClassWithClassDefinitions {

}

An example of a suite file with two different <test> tags.

import com.rationaleemotions.annotations.XmlSuite;
import com.rationaleemotions.annotations.internal.XmlTest;

@XmlSuite(name = "Example_Suite",
    tests = {
        @XmlTest(name = "Example_Test_One", testClasses = {
            SampleTestCase.class,
        }),
        @XmlTest(name = "Example_Test_Two", testClasses = {
            SampleTestCase2.class,
        })
    }
)
public class SuiteClassWithTwoTestTags {
}

An example of a suite with groups

import com.rationaleemotions.annotations.XmlSuite;
import com.rationaleemotions.annotations.internal.XmlGroup;
import com.rationaleemotions.annotations.internal.XmlRun;
import com.rationaleemotions.annotations.internal.XmlTest;

@XmlSuite(name = "Example_Suite",
    groups = @XmlGroup(
        run = @XmlRun(include = "run")
    ),
    tests = {
        @XmlTest(name = "Example_Test",
            testClasses = {
                SampleTestCase.class,
                SampleTestCase2.class
            }
        )
    }
)
public class SuiteClassWithGroupsAtSuiteLevel {

}

An example of a suite with group definitions

import com.rationaleemotions.annotations.XmlSuite;
import com.rationaleemotions.annotations.internal.XmlDefine;
import com.rationaleemotions.annotations.internal.XmlGroup;
import com.rationaleemotions.annotations.internal.XmlRun;
import com.rationaleemotions.annotations.internal.XmlTest;

@XmlSuite(name = "Example_Suite",
    tests = {
        @XmlTest(name = "Example_Test",
            groups = @XmlGroup(
                define = @XmlDefine(
                    name = "runtime",
                    include = "run"
                ),
                run = @XmlRun(
                    include = "runtime"
                )
            ),
            testClasses = {
                SampleTestCase.class,
                SampleTestCase2.class
            }
        )
    }
)
public class SuiteClassWithGroupsDefinitionSpecifiedAtTestTagLevel {

}

An example of specifying parameters at <suite> level

import com.rationaleemotions.annotations.XmlSuite;
import com.rationaleemotions.annotations.internal.XmlParameter;

@XmlSuite(
    name = "Example_Suite",
    parameters = {
        @XmlParameter(name = "age", value = "24")
    },
    testClasses = {SampleTestCase.class}
)
public class SuiteClassWithSuiteLevelParameters {

}

An example of specifying parameters at <test> level

import com.rationaleemotions.annotations.XmlSuite;
import com.rationaleemotions.annotations.internal.XmlParameter;
import com.rationaleemotions.annotations.internal.XmlTest;

@XmlSuite(
    name = "Example_Suite",
    tests = {
        @XmlTest(name = "Example_Test_Three",
            parameters = {
                @XmlParameter(name = "age", value = "24")
            },
            testClasses = {SampleTestCase.class}
        )
    }
)
public class SuiteClassWithTestTagLevelParameters {

}

An example of specifying parameters for individual classes

import com.rationaleemotions.annotations.XmlSuite;
import com.rationaleemotions.annotations.internal.XmlClass;
import com.rationaleemotions.annotations.internal.XmlParameter;
import com.rationaleemotions.annotations.internal.XmlTest;

@XmlSuite(
    name = "Example_Suite",
    tests = {
        @XmlTest(name = "Example_Test_One",
            classDefinitions = {
                @XmlClass(classToRun = SampleTestCase.class,
                    parameters = {
                        @XmlParameter(name = "age", value = "42")
                    }
                )
            }
        )
    }
)
public class SuiteClassWithClassLevelParameters {

}

sangrahah's People

Contributors

krmahadevan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gyyfifafans

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.