Skip to content

Commit a348d37

Browse files
committed
minor updates
1 parent 2fb395b commit a348d37

File tree

16 files changed

+337
-255
lines changed

16 files changed

+337
-255
lines changed

README.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,55 @@
22

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

5+
## Installation
6+
7+
- [Apache Maven](maven.apache.org)
8+
```
9+
<dependency>
10+
<groupId>com.hackerrank.applications</groupId>
11+
<artifactId>junit-ordered-test-runner</artifactId>
12+
<version>1.0.0</version>
13+
</dependency>
14+
```
15+
16+
- [Gradle Groovy DSL](gradle.org)
17+
```
18+
compile 'com.hackerrank.applications:junit-ordered-test-runner:1.0.0'
19+
```
20+
21+
- [Gradle Kotlin DSL](github.com/gradle/kotlin-dsl)
22+
```
23+
compile(group = "com.hackerrank.applications", name = "junit-ordered-test-runner", version = "1.0.0")
24+
```
25+
26+
- [Scala SBT](scala-sbt.org)
27+
```
28+
libraryDependencies += "com.hackerrank.applications" % "junit-ordered-test-runner" % "1.0.0"
29+
```
30+
31+
- [Apache Ivy](ant.apache.org/ivy/)
32+
```
33+
<dependency org="com.hackerrank.applications" name="junit-ordered-test-runner" rev="1.0.0" />
34+
```
35+
36+
- [Groovy Grape](groovy-lang.org/grape.html)
37+
```
38+
@Grapes(
39+
@Grab(group='com.hackerrank.applications', module='junit-ordered-test-runner', version='1.0.0')
40+
)
41+
```
42+
43+
- [Apache Builder](buildr.apache.org)
44+
```
45+
'com.hackerrank.applications:junit-ordered-test-runner:jar:1.0.0'
46+
```
47+
548
## Sample Usage
649

750
- 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.
851
- Run the tests with `TestWatcher` rule using `@Rule` annotation.
9-
- Register the test class using the `registerClass` method of TestWatcher in the `@BeforeClass` setup.
10-
- Finally, invoke the `createReport` method of TestWatcher in the `@AfterClass` setup.
52+
- Register the test class using the `registerClass` method of `TestWatcher` in the `@BeforeClass` setup.
53+
- Finally, invoke the `createReport` method of `TestWatcher` in the `@AfterClass` setup.
1154

1255
For example,
1356

@@ -53,7 +96,7 @@ public class SampleOrderedTest {
5396

5497
Also,
5598

56-
- 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.
99+
- 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`.
57100

58101
For example,
59102

@@ -76,6 +119,8 @@ public class SampleOrderedTest {
76119
@Test
77120
public void startTest() {
78121
JUnitCore.runClasses(TestHelper.class);
122+
123+
assertTrue(TestWatchman.watchman.allTestsSucceeded());
79124
}
80125

81126
@RunWith(OrderedTestRunner.class)

pom.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.hackerrank.applications</groupId>
66
<artifactId>junit-ordered-test-runner</artifactId>
7-
<version>1.0</version>
7+
<version>1.0.0</version>
88
<packaging>jar</packaging>
99

1010
<name>${project.groupId}:${project.artifactId}</name>
@@ -32,19 +32,19 @@
3232
<organizationUrl>https://www.hackerrank.com/</organizationUrl>
3333
</developer>
3434
</developers>
35-
35+
3636
<scm>
3737
<connection>scm:git:git://github.com/interviewstreet/junit-ordered-test-runner.git</connection>
3838
<developerConnection>scm:git:ssh://github.com:interviewstreet/junit-ordered-test-runner.git</developerConnection>
3939
<url>http://github.com/interviewstreet/junit-ordered-test-runner/tree/master</url>
4040
</scm>
41-
41+
4242
<distributionManagement>
4343
<snapshotRepository>
4444
<id>ossrh</id>
4545
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
4646
</snapshotRepository>
47-
47+
4848
<repository>
4949
<id>ossrh</id>
5050
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
@@ -80,14 +80,14 @@
8080
<type>jar</type>
8181
</dependency>
8282
</dependencies>
83-
83+
8484
<build>
8585
<plugins>
8686
<plugin>
8787
<groupId>org.apache.maven.plugins</groupId>
8888
<artifactId>maven-source-plugin</artifactId>
8989
<version>3.0.1</version>
90-
90+
9191
<executions>
9292
<execution>
9393
<id>attach-sources</id>
@@ -97,12 +97,12 @@
9797
</execution>
9898
</executions>
9999
</plugin>
100-
100+
101101
<plugin>
102102
<groupId>org.apache.maven.plugins</groupId>
103103
<artifactId>maven-javadoc-plugin</artifactId>
104104
<version>3.0.1</version>
105-
105+
106106
<executions>
107107
<execution>
108108
<id>attach-javadocs</id>
@@ -112,7 +112,7 @@
112112
</execution>
113113
</executions>
114114
</plugin>
115-
115+
116116
<plugin>
117117
<groupId>org.apache.maven.plugins</groupId>
118118
<artifactId>maven-gpg-plugin</artifactId>

src/main/java/com/hackerrank/test/utility/Color.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
package com.hackerrank.test.utility;
1717

1818
/**
19-
*
2019
* @author Abhimanyu Singh
2120
22-
* @version 1.0
23-
* @since 1.0
21+
* @version 1.0.0
22+
* @since 1.0.0
2423
*/
2524
public class Color {
2625

src/main/java/com/hackerrank/test/utility/NumberFormatter.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,28 @@
1818
import java.math.BigDecimal;
1919

2020
/**
21-
*
2221
* @author Abhimanyu Singh
2322
24-
* @version 1.0
25-
* @since 1.0
23+
* @version 1.0.0
24+
* @since 1.0.0
2625
*/
2726
public class NumberFormatter {
2827

2928
/**
30-
*
3129
* @param value double value
3230
* @param precision number of decimal places
3331
* @return string representation of rounded double to fixed decimal places
3432
*/
3533
public static String stringValue(double value, int precision) {
36-
return new BigDecimal(value)
37-
.setScale(precision, BigDecimal.ROUND_HALF_EVEN)
38-
.toString();
34+
return new BigDecimal(value).setScale(precision, BigDecimal.ROUND_HALF_EVEN).toString();
3935
}
4036

4137
/**
42-
*
4338
* @param value double value
4439
* @param precision number of decimal places
4540
* @return rounded double to fixed decimal places
4641
*/
4742
public static double doubleValue(double value, int precision) {
48-
return new BigDecimal(value)
49-
.setScale(precision, BigDecimal.ROUND_HALF_EVEN)
50-
.doubleValue();
43+
return new BigDecimal(value).setScale(precision, BigDecimal.ROUND_HALF_EVEN).doubleValue();
5144
}
5245
}

src/main/java/com/hackerrank/test/utility/Order.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,15 @@
2121
import java.lang.annotation.Target;
2222

2323
/**
24-
*
2524
* @author Abhimanyu Singh
2625
27-
* @version 1.0
28-
* @since 1.0
26+
* @version 1.0.0
27+
* @since 1.0.0
2928
*/
3029
@Retention(RetentionPolicy.RUNTIME)
31-
@Target({
32-
ElementType.METHOD
33-
})
30+
@Target({ElementType.METHOD})
3431
public @interface Order {
3532

36-
/**
37-
*
38-
* @return order
39-
*/
33+
/** @return order */
4034
public int value();
4135
}

src/main/java/com/hackerrank/test/utility/OrderedTestRunner.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,32 @@
1515
*/
1616
package com.hackerrank.test.utility;
1717

18+
import static java.util.stream.Collectors.toList;
19+
1820
import java.util.HashMap;
1921
import java.util.List;
2022
import java.util.Map;
21-
import static java.util.stream.Collectors.toList;
2223
import org.junit.runners.BlockJUnit4ClassRunner;
2324
import org.junit.runners.model.FrameworkMethod;
2425
import org.junit.runners.model.InitializationError;
2526

2627
/**
27-
*
2828
* @author Abhimanyu Singh
2929
30-
* @version 1.0
31-
* @since 1.0
30+
* @version 1.0.0
31+
* @since 1.0.0
3232
*/
3333
public class OrderedTestRunner extends BlockJUnit4ClassRunner {
3434

3535
/**
36-
*
3736
* @param clazz test class
3837
* @throws InitializationError initialization error
3938
*/
4039
public OrderedTestRunner(Class<?> clazz) throws InitializationError {
4140
super(clazz);
4241
}
4342

44-
/**
45-
*
46-
* @return test methods ordered by execution order
47-
*/
43+
/** @return test methods ordered by execution order */
4844
@Override
4945
protected List<FrameworkMethod> computeTestMethods() {
5046
Map<FrameworkMethod, Integer> orders = new HashMap();

src/main/java/com/hackerrank/test/utility/ReportGenerator.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,31 @@
1515
*/
1616
package com.hackerrank.test.utility;
1717

18+
import static java.util.stream.Collectors.toList;
19+
import static org.apache.commons.lang.exception.ExceptionUtils.getStackTrace;
20+
1821
import java.io.File;
1922
import java.io.FileWriter;
2023
import java.io.IOException;
2124
import java.util.List;
2225
import java.util.Map;
2326
import java.util.Map.Entry;
24-
import static java.util.stream.Collectors.toList;
2527
import java.util.stream.Stream;
26-
import static org.apache.commons.lang.exception.ExceptionUtils.getStackTrace;
2728
import org.jdom.Attribute;
2829
import org.jdom.Document;
2930
import org.jdom.Element;
3031
import org.jdom.output.Format;
3132
import org.jdom.output.XMLOutputter;
3233

3334
/**
34-
*
3535
* @author Abhimanyu Singh
3636
37-
* @version 1.0
38-
* @since 1.0
37+
* @version 1.0.0
38+
* @since 1.0.0
3939
*/
4040
public class ReportGenerator {
4141

4242
/**
43-
*
4443
* @param clazz test class
4544
* @param suiteTests test methods in the class
4645
*/
@@ -50,7 +49,8 @@ public static void createReport(Class<?> clazz, Map<String, List<TestObject>> su
5049
Document report = new Document();
5150

5251
if (suiteTests.containsKey(className)) {
53-
report.setRootElement(ReportGenerator.createReport(className, suiteTests.get(className)));
52+
report.setRootElement(
53+
ReportGenerator.createReport(className, suiteTests.get(className)));
5454
} else {
5555
Element testsuites = new Element("testsuites");
5656

@@ -101,21 +101,19 @@ public static void createReport(Class<?> clazz, Map<String, List<TestObject>> su
101101
outputter.setFormat(Format.getPrettyFormat());
102102

103103
try {
104-
outputter.output(report, new FileWriter(new File(reportPath + "/TEST-" + className + ".xml")));
104+
outputter.output(
105+
report, new FileWriter(new File(reportPath + "/TEST-" + className + ".xml")));
105106
} catch (IOException ex) {
106107
System.out.println(
107108
String.join(
108109
"\n",
109110
Stream.of(getStackTrace(ex).split("\n"))
110111
.map(str -> Color.RED + str + Color.RESET)
111-
.collect(toList())
112-
)
113-
);
112+
.collect(toList())));
114113
}
115114
}
116115

117116
/**
118-
*
119117
* @param className test class
120118
* @param tests test methods in the class
121119
* @return XML element for a test report

0 commit comments

Comments
 (0)