com.hackerrank.applications:junit-ordered-test-runner

An application to provide support for executing tests in the specific order and generate the customized XML report.

License

License

Categories

Categories

JUnit Unit Testing
GroupId

GroupId

com.hackerrank.applications
ArtifactId

ArtifactId

junit-ordered-test-runner
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

com.hackerrank.applications:junit-ordered-test-runner
An application to provide support for executing tests in the specific order and generate the customized XML report.
Project URL

Project URL

http://github.com/interviewstreet/junit-ordered-test-runner/tree/master
Source Code Management

Source Code Management

http://github.com/interviewstreet/junit-ordered-test-runner/tree/master

Download junit-ordered-test-runner

How to add to project

<!-- https://jarcasting.com/artifacts/com.hackerrank.applications/junit-ordered-test-runner/ -->
<dependency>
    <groupId>com.hackerrank.applications</groupId>
    <artifactId>junit-ordered-test-runner</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.hackerrank.applications/junit-ordered-test-runner/
implementation 'com.hackerrank.applications:junit-ordered-test-runner:1.0.2'
// https://jarcasting.com/artifacts/com.hackerrank.applications/junit-ordered-test-runner/
implementation ("com.hackerrank.applications:junit-ordered-test-runner:1.0.2")
'com.hackerrank.applications:junit-ordered-test-runner:jar:1.0.2'
<dependency org="com.hackerrank.applications" name="junit-ordered-test-runner" rev="1.0.2">
  <artifact name="junit-ordered-test-runner" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.hackerrank.applications', module='junit-ordered-test-runner', version='1.0.2')
)
libraryDependencies += "com.hackerrank.applications" % "junit-ordered-test-runner" % "1.0.2"
[com.hackerrank.applications/junit-ordered-test-runner "1.0.2"]

Dependencies

compile (4)

Group / Artifact Type Version
junit : junit jar 4.12
com.fasterxml.jackson.core : jackson-databind jar 2.9.6
commons-lang : commons-lang jar 2.6
org.jdom : jdom jar 1.1

Project Modules

There are no modules declared in this project.

JUnit Ordered Test Runner

An application to provide support for executing tests in the specific order and generate the customized XML report.

Installation

<dependency>
    <groupId>com.hackerrank.applications</groupId>
    <artifactId>junit-ordered-test-runner</artifactId>
    <version>1.0.2</version>
</dependency>
compile 'com.hackerrank.applications:junit-ordered-test-runner:1.0.2'
compile(group = "com.hackerrank.applications", name = "junit-ordered-test-runner", version = "1.0.2")
libraryDependencies += "com.hackerrank.applications" % "junit-ordered-test-runner" % "1.0.2"
<dependency org="com.hackerrank.applications" name="junit-ordered-test-runner" rev="1.0.2" />
@Grapes(
  @Grab(group='com.hackerrank.applications', module='junit-ordered-test-runner', version='1.0.2')
)
'com.hackerrank.applications:junit-ordered-test-runner:jar:1.0.2'

Sample Usage

  • The OrderedTestRunner should be used to run the test. The order of each test can be set by the @Order annotation. The test with lower order value is run first.
  • Run the tests with TestWatcher rule using @Rule annotation.
  • Register the test class using the registerClass method of TestWatcher in the @BeforeClass setup.
  • Finally, invoke the createReport method of TestWatcher in the @AfterClass setup.

For example,

@RunWith(OrderedTestRunner.class)
public class SampleOrderedTest {

    @Rule
    public TestWatcher watchman = TestWatchman.watchman;

    public SampleOrderedTest() {
    }

    @BeforeClass
    public static void setUpClass() {
        TestWatchman.watchman.registerClass(SampleOrderedTest.class);
    }

    @AfterClass
    public static void tearDownClass() {
        TestWatchman.watchman.createReport(SampleOrderedTest.class);
    }

    @Test
    @Order(1)
    public void firstTest() {
        assertTrue(0 == 0);
    }

    @Test
    @Order(2)
    public void secondTest() {
        assertEquals(1, 1);
    }

    @Test
    @Ordered(3)
    public void thirdTest() {
        assertNotEquals(1, null);
    }
}

Also,

  • If a Runner is already being used to run the tests, then, an inner class can be used to run with OrderedTestRunner. Tests can be triggered using the JUnitCore.runClasses method. In this case, the test is always passing, so optional check can be performed using allTestSucceeded.

For example,

public class SampleOrderedTest {

    public SampleOrderedTest() {
    }

    @BeforeClass
    public static void setUpClass() {
        TestWatchman.watchman.registerClass(SampleOrderedTest.class);
    }

    @AfterClass
    public static void tearDownClass() {
        TestWatchman.watchman.createReport(SampleOrderedTest.class);
    }

    @Test
    public void startTest() {
        JUnitCore.runClasses(TestHelper.class);

        assertTrue(TestWatchman.watchman.allTestsSucceeded());
    }

    @RunWith(OrderedTestRunner.class)
    public static class TestHelper {

        @Rule
        public TestWatcher watchman = TestWatchman.watchman;

        @Test
        @Order(1)
        public void firstTest() {
            assertTrue(0 == 0);
        }

        @Test
        @Order(3)
        public void thirdTest() {
            assertNotEquals(1, null);
        }

        @Test
        @Order(2)
        public void secondTest() {
            assertEquals(1, 1);
        }
    }
}

And,

  • When some tests are not assigned an order, then, these are run after the tests with an assigned order.

You can refer the given test examples for better understanding of writing tests with OrderedTestRunner.

Report Generation

  • The TestWatcher generates an XML report in the target/hackerrank-report directory. The filename is TEST-{test-class-canonical-name}.xml.
  • When running tests in a suite, suite report, as well as individual test reports, will be generated.

Building Project

  • Use mvn clean build to build the project.
  • Use mvn clean test to run the tests.
  • Use mvn clean test -Dtest=TestSuite to run the suite.
com.hackerrank.applications

HackerRank

Match Every Developer to the Right Job.

Versions

Version
1.0.2
1.0.1
1.0.0