JUnitParams Documentation

repository·master·Indexed 21 days ago

https://github.com/pragmatists/junitparams

A library for JUnit 4.12+ that enables writing parameterized tests by passing parameters directly to test methods via the @Parameters annotation and JUnitParamsRunner. Supports CSV strings, provider classes, and integration with Spring framework version 4.2 and above.

Tokens
472
Snippets
2
Records
3
Agent score
25%

What's inside JUnitParams

  1. Quickstart: Install JUnitParams

    master

    To use JUnitParams in your project, add the following dependency to your build configuration file.

    ### Maven
    ```xml
    <dependency>
      <groupId>pl.pragmatists</groupId>
      <artifactId>JUnitParams</artifactId>
      <version>1.1.1</version>
      <scope>test</scope>
    </dependency>

    Gradle

    testCompile 'pl.pragmatists:JUnitParams:1.1.1'
  2. How to write parameterised tests with JUnitParams

    master

    JUnitParams provides a JUnitParamsRunner that allows you to pass parameters directly into your test method arguments using the @Parameters annotation. This is more concise than standard JUnit 4 parameterised tests because it avoids the need for class-level fields and constructors.

    Key features:

    • Parameters are passed directly to the test method parameters.
    • You can mix parameterised and non-parameterised methods in the same class.
    • Parameters can be provided as a CSV string via @Parameters or from a dedicated provider class.
    • You can use a method within the same test class to provide parameters.
    @RunWith(JUnitParamsRunner.class)
    public class PersonTest {
    
      @Test
      @Parameters({"17, false", 
                   "22, true" })
      public void personIsAdult(int age, boolean valid) throws Exception {
        assertThat(new Person(age).isAdult(), is(valid));
      }
      
    }