JUnit STDIO

A JUnit extension to run tests with piping file inputs to STDIN and validation against STDOUT.

License

License

Categories

Categories

JUnit Unit Testing
GroupId

GroupId

hu.webhejj.junit.stdio
ArtifactId

ArtifactId

junit-stdio
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

JUnit STDIO
A JUnit extension to run tests with piping file inputs to STDIN and validation against STDOUT.
Project URL

Project URL

https://github.com/gnagy/junit-stdio
Source Code Management

Source Code Management

https://github.com/gnagy/junit-stdio

Download junit-stdio

How to add to project

<!-- https://jarcasting.com/artifacts/hu.webhejj.junit.stdio/junit-stdio/ -->
<dependency>
    <groupId>hu.webhejj.junit.stdio</groupId>
    <artifactId>junit-stdio</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/hu.webhejj.junit.stdio/junit-stdio/
implementation 'hu.webhejj.junit.stdio:junit-stdio:1.0.0'
// https://jarcasting.com/artifacts/hu.webhejj.junit.stdio/junit-stdio/
implementation ("hu.webhejj.junit.stdio:junit-stdio:1.0.0")
'hu.webhejj.junit.stdio:junit-stdio:jar:1.0.0'
<dependency org="hu.webhejj.junit.stdio" name="junit-stdio" rev="1.0.0">
  <artifact name="junit-stdio" type="jar" />
</dependency>
@Grapes(
@Grab(group='hu.webhejj.junit.stdio', module='junit-stdio', version='1.0.0')
)
libraryDependencies += "hu.webhejj.junit.stdio" % "junit-stdio" % "1.0.0"
[hu.webhejj.junit.stdio/junit-stdio "1.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

JUnit STDIO

A JUnit extension to run tests with piping file inputs to STDIN and validation against STDOUT.

This can be useful for example when writing solutions as unit tests for coding challenges such as on HackerRank.

Example:

@RunWith(StdioSuite.class)
@StdioInputs({"000", "001"})
public class ToUpperTest {

    @Test
    public void testToUpper() throws Exception {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        String line = "";
        while ((line = stdin.readLine()) != null){
            System.out.println(line.toUpperCase());
        }
    }
}

JUnit will run testToUpper() two times based on the @StdioInputs annotation. The test runner first reads in input000.txt, pipes it to STDIN of the test and then compares its STDOUT to output000.txt. Then, the same is done for input001.txt and output001.txt respectively. The files are read as resources from the CLASSPATH in the same package where the class under test is located.

See also the unit test that comes with this project.

Downloads

Available on Maven Central.

License

Copyright 2015 Gergely Nagy [email protected]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Versions

Version
1.0.0