### Usage Example for Custom Date Parameter Conversion Source: https://github.com/pragmatists/junitparams/blob/master/RELEASES.md Demonstrates how to use a custom annotation like @DateParam in a test method to automatically convert string parameters to Date objects. ```java @Test @Parameters({"2012-12-01"}) public void testWithConvertedDate(@DateParam Date date) { assertThat(...); } ``` -------------------------------- ### Parameterized Test Example with JUnitParams Source: https://github.com/pragmatists/junitparams/blob/master/README.md Demonstrates a basic parameterized test using JUnitParams. Parameters are provided as a CSV string directly in the @Parameters annotation. ```java @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)); } } ``` -------------------------------- ### Get runner description Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Retrieves the description for the current runner instance. ```java getDescription() ``` -------------------------------- ### Spring Integration Setup Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Integrate JUnitParams with Spring by initializing a TestContextManager. This allows you to use Spring's test framework features within your parameterized tests. ```java private TestContextManager testContextManager; @Before public void init() throws Exception { this.testContextManager = new TestContextManager(getClass()); this.testContextManager.prepareTestInstance(this); } ``` -------------------------------- ### Parameters Annotation with External Source Class Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/Parameters.html Use the 'source' element to specify an external class that provides parameter values. This class must contain public static methods starting with 'provide' that return Object[]. ```java @Parameters(source = PeopleProvider.class) ``` -------------------------------- ### Spring Integration Test with JUnitParams Source: https://context7.com/pragmatists/junitparams/llms.txt This example shows how to use JUnitParams with Spring's test context. It requires manual initialization of TestContextManager in a @Before method. Use @Autowired to inject Spring beans. ```java @RunWith(JUnitParamsRunner.class) @ContextConfiguration(classes = {TestConfig.class}) public class SpringIntegrationTest { @Autowired private UserService userService; @Autowired private UserRepository userRepository; private TestContextManager testContextManager; @Before public void setUp() throws Exception { // Initialize Spring test context manually this.testContextManager = new TestContextManager(getClass()); this.testContextManager.prepareTestInstance(this); } @Test @Parameters({ "john@example.com, John Doe", "jane@example.com, Jane Smith" }) public void shouldCreateUserWithSpringServices(String email, String name) { User user = userService.createUser(email, name); assertThat(user).isNotNull(); assertThat(user.getEmail()).isEqualTo(email); assertThat(userRepository.findByEmail(email)).isPresent(); } @Test @Parameters(method = "getUserTestData") public void shouldValidateUserWithRepository(User user, boolean shouldExist) { if (shouldExist) { userRepository.save(user); } boolean exists = userRepository.existsByEmail(user.getEmail()); assertThat(exists).isEqualTo(shouldExist); } private Object[] getUserTestData() { return new Object[]{ new Object[]{new User("existing@test.com", "Existing"), true}, new Object[]{new User("new@test.com", "New User"), false} }; } } ``` -------------------------------- ### Create parameter array shortcut Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Utility method to return an array of objects for parameter injection. ```java $(Object... params) ``` -------------------------------- ### Provide Parameters via Methods Source: https://context7.com/pragmatists/junitparams/llms.txt Use a provider method returning Object[] to supply test data. Methods can be explicitly referenced or automatically discovered via the parametersFor naming convention. ```java @RunWith(JUnitParamsRunner.class) public class MathOperationsTest { // Explicit method reference @Test @Parameters(method = "additionTestData") public void shouldAdd(int a, int b, int expected) { assertThat(a + b).isEqualTo(expected); } private Object[] additionTestData() { return new Object[]{ new Object[]{1, 1, 2}, new Object[]{2, 3, 5}, new Object[]{-1, 1, 0}, new Object[]{100, 200, 300} }; } // Implicit method naming convention (parametersFor + TestMethodName) @Test @Parameters public void shouldMultiply(int a, int b, int expected) { assertThat(a * b).isEqualTo(expected); } private Object[] parametersForShouldMultiply() { return new Object[]{ new Object[]{2, 3, 6}, new Object[]{0, 100, 0}, new Object[]{-2, 3, -6} }; } // Multiple methods providing parameters @Test @Parameters(method = "positiveNumbers, negativeNumbers") public void shouldCalculateAbsoluteValue(int input, int expected) { assertThat(Math.abs(input)).isEqualTo(expected); } private Object[] positiveNumbers() { return new Object[]{new Object[]{5, 5}, new Object[]{0, 0}}; } private Object[] negativeNumbers() { return new Object[]{new Object[]{-5, 5}, new Object[]{-100, 100}}; } } ``` -------------------------------- ### GET /junitparams/internal/ParameterisedTestClassRunner/testMethodFor Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/internal/class-use/TestMethod.html Retrieves a cached TestMethod object associated with a specific FrameworkMethod. ```APIDOC ## GET /junitparams/internal/ParameterisedTestClassRunner/testMethodFor ### Description Returns a cached TestMethod object related to the given FrameworkMethod. ### Method GET ### Endpoint /junitparams/internal/ParameterisedTestClassRunner/testMethodFor ### Parameters #### Query Parameters - **method** (org.junit.runners.model.FrameworkMethod) - Required - The framework method to retrieve the TestMethod for. ### Response #### Success Response (200) - **TestMethod** (object) - The cached TestMethod object. ``` -------------------------------- ### GET /junitparams/TestMethod/testMethodFor Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/class-use/TestMethod.html Retrieves a cached TestMethod object associated with a specific FrameworkMethod. ```APIDOC ## GET /junitparams/TestMethod/testMethodFor ### Description Returns a cached TestMethod object related to the given FrameworkMethod. ### Method GET ### Endpoint /junitparams/ParameterisedTestClassRunner/testMethodFor ### Parameters #### Query Parameters - **method** (org.junit.runners.model.FrameworkMethod) - Required - The framework method to retrieve the TestMethod for. ### Response #### Success Response (200) - **TestMethod** (object) - The cached TestMethod object. ``` -------------------------------- ### Create Object Array Shortcut Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Utility method to quickly create an Object array from provided parameters. ```java public static Object[] $(Object... params) ``` -------------------------------- ### Describe test method Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Returns a description for a specific framework method. ```java describeMethod(org.junit.runners.model.FrameworkMethod method) ``` -------------------------------- ### GET /junitparams/internal/ParameterisedTestClassRunner/getTestMethod Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/internal/ParameterisedTestClassRunner.html Retrieves a cached TestMethod object associated with a specific FrameworkMethod to ensure parameters are retrieved only once. ```APIDOC ## GET /junitparams/internal/ParameterisedTestClassRunner/getTestMethod ### Description Returns a cached TestMethod object related to the given FrameworkMethod. This object has all the params already retrieved, so use this one and not TestMethod's constructor if you want to have everything retrieved once and cached. ### Parameters #### Path Parameters - **method** (FrameworkMethod) - Required - The FrameworkMethod instance to retrieve the cached TestMethod for. ### Response #### Success Response (200) - **TestMethod** (Object) - A cached TestMethod instance. ``` -------------------------------- ### Parameterize tests with constructor arguments Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Return a list of constructor arguments to automatically instantiate objects, noting that automatic refactoring will not work. ```java @Test @Parameters public void cartoonCharacters(Person character) { ... } private List parametersForCartoonCharacters() { return Arrays.asList( $(0, "Tarzan"), $(20, "Jane") ); } ``` -------------------------------- ### External Parameter Provider Class Source: https://context7.com/pragmatists/junitparams/llms.txt Organize parameter providers into separate classes. Source methods must be public static and named 'provide*'. ```java public class PersonDataProvider { public static Object[] provideAdults() { return new Object[]{ new Object[]{new Person("John", 25), true}, new Object[]{new Person("Jane", 30), true} }; } public static Object[] provideMinors() { return new Object[]{ new Object[]{new Person("Tom", 15), false}, new Object[]{new Person("Alice", 10), false} }; } } ``` ```java @RunWith(JUnitParamsRunner.class) public class PersonValidationTest { // Uses all methods starting with 'provide' in the source class @Test @Parameters(source = PersonDataProvider.class) public void shouldValidateAdultStatus(Person person, boolean isAdult) { assertThat(person.isAdult()).isEqualTo(isAdult); } // Use enum class as source - tests all enum values @Test @Parameters(source = DayOfWeek.class) public void shouldHandleAllDays(DayOfWeek day) { assertThat(day).isNotNull(); } } ``` -------------------------------- ### Implement ParametersProvider with FrameworkMethod Source: https://github.com/pragmatists/junitparams/blob/master/RELEASES.md Enhances ParametersProvider with a FrameworkMethod object, providing access to method-specific information like annotations. This is a breaking change requiring migration for custom parameter providers. ```java public static class MethodNameReader implements ParametersProvider { private FrameworkMethod frameworkMethod; @Override public void initialize(CustomParameters parametersAnnotation, FrameworkMethod frameworkMethod) { this.frameworkMethod = frameworkMethod; } @Override public Object[] getParameters() { return new Object[]{frameworkMethod.getName()}; } } ``` -------------------------------- ### TestMethod Class Overview Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/TestMethod.html Provides an overview of the TestMethod class, its inheritance, and a summary of its fields, constructors, and methods. ```APIDOC ## TestMethod Class ### Description Represents a test method within the JUnitParams framework, providing access to its annotations, parameters, and other metadata. ### Class Hierarchy `java.lang.Object` `junitparams.TestMethod` ### Field Summary - `protected org.junit.runners.model.FrameworkMethod frameworkMethod` The underlying JUnit FrameworkMethod. ### Constructor Summary - `TestMethod(org.junit.runners.model.FrameworkMethod method, org.junit.runners.model.TestClass testClass)` Constructs a new TestMethod instance. ### Method Summary - `Annotation[] annotations()` Returns an array of annotations present on the test method. - `boolean equals(Object obj)` Indicates whether some other object is "equal to" this one. - `int hashCode()` Returns a hash code value for the object. - `boolean isIgnored()` Checks if the test method is ignored. - `boolean isNotIgnored()` Checks if the test method is not ignored. - `boolean isParameterised()` Checks if the test method is parameterized. - `static List listFrom(List annotatedMethods, org.junit.runners.model.TestClass testClass)` Creates a list of TestMethod instances from a list of FrameworkMethods. - `String name()` Returns the name of the test method. ``` -------------------------------- ### computeFrameworkMethods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/ParameterisedTestClassRunner.html Retrieves a list of FrameworkMethods, handling both parameterised and non-parameterised methods. ```APIDOC ## computeFrameworkMethods ### Description Returns a list of FrameworkMethods. Handles both parameterised methods (counts them as many times as many paramsets they have) and nonparameterised methods (just counts them once). ### Parameters - **firstTimeJustToGetNames** (boolean) - Required - If true, returns only parameterised methods once, used by JUnit for building the tree of test names without the params. ### Response - **List** - A list of FrameworkMethod objects. ``` -------------------------------- ### getDescription Method Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/index-all.html Retrieves the description of a test. ```APIDOC ## getDescription Method ### Description Retrieves the description of the test. This method is part of the JUnit test execution lifecycle. ### Method junitparams.JUnitParamsRunner.getDescription() ### Returns - Description (Description) - The description of the test. ``` -------------------------------- ### JUnitParamsRunner Constructor Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Initializes a new instance of the JUnitParamsRunner class. ```APIDOC ## Constructor JUnitParamsRunner ### Description Initializes the runner for the specified test class. ### Parameters - **klass** (Class) - Required - The test class to be run. ### Throws - **org.junit.runners.model.InitializationError** - Thrown if the test class is malformed. ``` -------------------------------- ### ParameterisedTestClassRunner Class Overview Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/ParameterisedTestClassRunner.html Provides an overview of the ParameterisedTestClassRunner class, its purpose, and its inheritance hierarchy. ```APIDOC ## Class ParameterisedTestClassRunner ### Description Testclass-level functionalities to handle parameters from a JUnit runner class. ### Author: Pawel Lipinski ### Inheritance - java.lang.Object - junitparams.ParameterisedTestClassRunner ``` -------------------------------- ### stringify Method Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/internal/Utils.html Converts a parameter set and its index into a string representation. ```APIDOC ## stringify ### Description Converts a given parameter set object and its corresponding index into a string representation. ### Parameters - **paramSet** (Object) - Required - The parameter set object to be stringified. - **paramIdx** (int) - Required - The index of the parameter set. ### Response - **String** - The stringified representation of the parameter set. ``` -------------------------------- ### TestMethod Class Overview Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/TestMethod.html Overview of the TestMethod class, including its fields, constructor, and methods. ```APIDOC ## TestMethod Class ### Description Represents a test method within the JUnit framework, enhanced with parameters from JUnitParams. ### Field Detail #### frameworkMethod protected org.junit.runners.model.FrameworkMethod **frameworkMethod** ### Constructor Detail #### TestMethod public **TestMethod**(org.junit.runners.model.FrameworkMethod method, org.junit.runners.model.TestClass testClass) ### Method Detail #### name public [String](http://download.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true "class or interface in java.lang") **name**() * * * #### listFrom public static [List](http://download.oracle.com/javase/6/docs/api/java/util/List.html?is-external=true "class or interface in java.util")<[TestMethod](../junitparams/TestMethod.html "class in junitparams") **listFrom**([List](http://download.oracle.com/javase/6/docs/api/java/util/List.html?is-external=true "class or interface in java.util") annotatedMethods, org.junit.runners.model.TestClass testClass) * * * #### hashCode public int **hashCode**() **Overrides:** `[hashCode](http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#hashCode() "class or interface in java.lang")` in class `[Object](http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true "class or interface in java.lang")` * * * #### equals public boolean **equals**([Object](http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true "class or interface in java.lang") obj) **Overrides:** `[equals](http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object) "class or interface in java.lang")` in class `[Object](http://download.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true "class or interface in java.lang")` * * * #### isIgnored public boolean **isIgnored**() * * * #### isNotIgnored public boolean **isNotIgnored**() * * * #### annotations public [Annotation](http://download.oracle.com/javase/6/docs/api/java/lang/annotation/Annotation.html?is-external=true "class or interface in java.lang.annotation")[] **annotations**() * * * #### isParameterised public boolean **isParameterised**() * * * ### Inherited Methods Includes methods from `java.lang.Object` such as `clone`, `finalize`, `getClass`, `notify`, `notifyAll`, `toString`, and `wait`. ``` -------------------------------- ### TestMethod Constructor Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/internal/TestMethod.html Details of the constructor used to create a TestMethod instance. ```APIDOC ## Constructor TestMethod ### Description Initializes a new instance of the `TestMethod` class. ### Parameters * **method** (org.junit.runners.model.FrameworkMethod) - The framework method to wrap. * **testClass** (org.junit.runners.model.TestClass) - The test class containing the method. ``` -------------------------------- ### Initialize JUnitParamsRunner Source: https://github.com/pragmatists/junitparams/wiki/Quickstart Annotate your test class with @RunWith(JUnitParamsRunner.class) to enable parameterization. ```java @RunWith(JUnitParamsRunner.class) public class PersonTest { ... ``` -------------------------------- ### Collect initialization errors Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Collects errors encountered during runner initialization. ```java collectInitializationErrors(List errors) ``` -------------------------------- ### IdentityMapper Class Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/internal/IdentityMapper.html Provides details about the IdentityMapper class, its constructors, and methods. ```APIDOC ## IdentityMapper Class ### Description A mapper that maps contents of a file to a set of parameters for test methods. It uses CSV-like parsing with strict column ordering matching the test method's arguments. ### Class Hierarchy - java.lang.Object - junitparams.mappers.IdentityMapper ### Implements - junitparams.DataMapper ### Constructor Summary - **IdentityMapper()**: Creates a new instance of IdentityMapper. ### Method Summary - **Object[] map(Reader reader)**: Maps file contents to parameters. ### Constructor Detail #### IdentityMapper ```java public IdentityMapper() ``` ### Method Detail #### map ```java public Object[] map(Reader reader) ``` **Description**: Maps file contents to parameters. **Parameters**: - **reader** (Reader) - The reader for the file content. ``` -------------------------------- ### Initialize JUnitParamsRunner Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Constructor for the JUnitParamsRunner class. ```java JUnitParamsRunner(Class klass) ``` -------------------------------- ### describeParameterisedMethod Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/ParameterisedTestClassRunner.html Returns the description of a parameterised method. ```APIDOC ## describeParameterisedMethod ### Description Returns description of a parameterised method. ### Parameters - **method** (FrameworkMethod) - Required - The test method ### Response - **Description** - Description of a method or null if it's not parameterised. ``` -------------------------------- ### File Parameters Annotation - Load from File System Source: https://context7.com/pragmatists/junitparams/llms.txt Load test parameters from a CSV file located on the file system. Parameters are passed directly to the test method. ```java @RunWith(JUnitParamsRunner.class) public class FileParametersTest { // Load from file system (relative to project root) // test.csv contents: "25,John\n30,Jane\n17,Tom" @Test @FileParameters("src/test/resources/test.csv") public void shouldLoadFromFileSystem(int age, String name) { assertThat(name).isNotEmpty(); assertThat(age).isGreaterThan(0); } // Load from classpath @Test @FileParameters("classpath:test.csv") public void shouldLoadFromClasspath(int age, String name) { assertThat(name).isNotEmpty(); } // CSV with header row - uses CsvWithHeaderMapper to skip first line // with_header.csv contents: "id,name\n1,John\n2,Jane" @Test @FileParameters(value = "classpath:with_header.csv", mapper = CsvWithHeaderMapper.class) public void shouldLoadCsvWithHeader(int id, String name) { assertThat(id).isGreaterThan(0); assertThat(name).isNotEmpty(); } // Custom file format with custom mapper @Test @FileParameters(value = "src/test/resources/people.dat", mapper = PersonMapper.class) public void shouldUseCustomMapper(Person person) { assertThat(person).isNotNull(); } } // Custom DataMapper implementation public class PersonMapper implements DataMapper { @Override public Object[] map(Reader reader) { List result = new ArrayList<>(); try (BufferedReader br = new BufferedReader(reader)) { String line; while ((line = br.readLine()) != null) { String[] parts = line.split(";"); Person person = new Person(parts[0], Integer.parseInt(parts[1])); result.add(new Object[]{person}); } } catch (IOException e) { throw new RuntimeException(e); } return result.toArray(); } } ``` -------------------------------- ### Implement Custom Parameters Provider Source: https://context7.com/pragmatists/junitparams/llms.txt Implement the ParametersProvider interface to fetch test data from external sources like databases. Use the @CustomParameters annotation to link the provider to a test method. ```java // Custom annotation @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @CustomParameters(provider = DatabaseParametersProvider.class) public @interface DatabaseParameters { String query(); String datasource() default "default"; } // Custom parameters provider public class DatabaseParametersProvider implements ParametersProvider { private String query; private String datasource; @Override public void initialize(DatabaseParameters annotation, FrameworkMethod frameworkMethod) { this.query = annotation.query(); this.datasource = annotation.datasource(); } @Override public Object[] getParameters() { // Load parameters from database List results = new ArrayList<>(); try (Connection conn = getConnection(datasource); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query)) { while (rs.next()) { results.add(new Object[]{ rs.getString("name"), rs.getInt("age"), rs.getBoolean("active") }); } } catch (SQLException e) { throw new RuntimeException("Failed to load test data", e); } return results.toArray(); } private Connection getConnection(String datasource) { // Connection logic return null; } } // Using custom provider @RunWith(JUnitParamsRunner.class) public class DatabaseDrivenTest { @Test @DatabaseParameters(query = "SELECT name, age, active FROM test_users") public void shouldTestUsersFromDatabase(String name, int age, boolean active) { User user = new User(name, age, active); assertThat(user.isValid()).isTrue(); } } ``` -------------------------------- ### Utils Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/internal/package-summary.html Provides utility methods for handling results of parameterised tests. ```APIDOC ## Class: Utils ### Description Some String utils to handle parameterised tests' results. ### Method N/A (This is a class description, not an endpoint) ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ### Response Example N/A ``` -------------------------------- ### Use @Parameters with a provider method Source: https://github.com/pragmatists/junitparams/wiki/Quickstart Specify a method name to supply test parameters, or use the naming convention parametersFor[MethodName]. ```java @Test @Parameters(method = "adultValues") public void personIsAdult(int age, boolean valid) throws Exception { assertEquals(valid, new Person(age).isAdult()); } private Object[] adultValues() { return new Object[]{ new Object[]{13, false}, new Object[]{17, false}, new Object[]{18, true}, new Object[]{22, true} }; } ``` ```java @Test @Parameters public void personIsAdult(int age, boolean valid) throws Exception { assertEquals(valid, new Person(age).isAdult()); } private Object[] parametersForPersonIsAdult() { return new Object[]{ new Object[]{13, false}, new Object[]{17, false}, new Object[]{18, true}, new Object[]{22, true} }; } ``` -------------------------------- ### Support Multiple Custom Annotations for Parameter Conversion Source: https://github.com/pragmatists/junitparams/blob/master/RELEASES.md Allows applying multiple custom annotations for parameter conversion in a left-to-right order. Ensure your custom converters are correctly implemented. ```java @Test @Parameters("2") public void useMultipleConvertersFromLeftToRight(@TimesTwo @PlusTwo Integer param) { assertThat(param).isEqualTo(2 * 2 + 2); } ``` -------------------------------- ### Utils Class Methods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/index-all.html Utility methods for handling parameterised test results. ```APIDOC ## stringify(Object, int) ### Description Provides string representation for objects, potentially used for parameterised test results. ### Method Static ### Endpoint N/A (Internal Java method) ### Parameters - **object** (Object) - The object to stringify. - **level** (int) - An integer level, possibly for controlling string representation depth. ### Response (String) - The string representation of the object. ``` -------------------------------- ### Parameterize tests with multiple methods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Use the method argument in @Parameters to specify multiple provider methods separated by commas. ```java @Test @Parameters(method = "menCharactes, womenCharacters") public void cartoonCharacters(int yearsInJungle, String person) { ... } private Object[] menCharacters() { return $( $(20, "Tarzan"), $(2, "Chip"), $(2, "Dale") ); } private Object[] womenCharacters() { return $( $(0, "Jane"), $(18, "Pocahontas") ); } ``` -------------------------------- ### JUnitParams Packages Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/overview-summary.html This section lists the main packages available in the JUnitParams library. ```APIDOC ## JUnitParams Packages Overview This documentation outlines the structure and available packages within the JUnitParams library. ### Packages - **junitparams**: The core package for parameterised testing functionalities. - **junitparams.converters**: Contains classes for converting parameter values. - **junitparams.internal**: Internal classes used by the JUnitParams framework. - **junitparams.mappers**: Classes related to mapping parameter data. ``` -------------------------------- ### ParameterisedTestClassRunner Constructor Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/ParameterisedTestClassRunner.html Details the constructor for the ParameterisedTestClassRunner class. ```APIDOC ## Constructor ### `ParameterisedTestClassRunner(org.junit.runners.model.TestClass testClass)` - **Description**: Creates a runner for a given test class. ``` -------------------------------- ### Utility Method $ Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html A static utility method used to create an array of objects from the provided parameters. ```APIDOC ## static Object[] $(Object... params) ### Description Shortcut for returning an array of objects. All parameters passed to this method are returned in an Object[] array. ### Parameters - **params** (Object...) - Required - The objects to be included in the array. ``` -------------------------------- ### Utils Class Documentation Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/internal/Utils.html Provides utility methods for handling parameterised test results in JUnitParams. ```APIDOC ## Class Utils ### Description Some String utils to handle parameterised tests' results. ### Author Pawel Lipinski ### Field Summary #### `static String REGEX_ALL_NEWLINES` ### Constructor Summary #### `Utils()` ### Method Summary #### `static String stringify(Object paramSet, int paramIdx)` * Description: Converts a parameter set to a string representation, potentially handling specific parameter indices. * Parameters: * `paramSet` (Object) - The parameter set to stringify. * `paramIdx` (int) - The index of the parameter to stringify. * Returns: A string representation of the specified parameter. ### Methods inherited from class java.lang.Object `clone`, `equals`, `finalize`, `getClass`, `hashCode`, `notify`, `notifyAll`, `toString`, `wait`, `wait`, `wait` ``` -------------------------------- ### Define a Person domain class Source: https://github.com/pragmatists/junitparams/wiki/Quickstart A simple POJO used for testing purposes. ```java public class Person { private int age; public Person(int age) { this.age = age; } public boolean isAdult() { return age >= 18; } @Override public String toString() { return "Person of age: " + age; } } ``` -------------------------------- ### Parameters Annotation with Method Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/Parameters.html Use the 'method' element to specify one or more methods within the test class that return parameter values. Multiple methods can be specified, separated by commas. ```java @Parameters(method = "examplaryPeople") ``` ```java @Parameters(method = "womenParams, menParams") ``` -------------------------------- ### ParameterisedTestClassRunner Methods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/ParameterisedTestClassRunner.html Details the methods available in the ParameterisedTestClassRunner class. ```APIDOC ## Methods ### `computeFrameworkMethods(boolean firstTimeJustToGetNames)` - **Returns**: `List` - **Description**: Returns a list of `FrameworkMethod`s. ### `computeTestMethods(org.junit.runners.model.TestClass testClass)` - **Returns**: `void` - **Description**: Computes the test methods for the given test class. ### `describeParameterisedMethod(org.junit.runners.model.FrameworkMethod method)` - **Returns**: `org.junit.runner.Description` - **Description**: Returns description of a parameterised method. ### `parameterisedMethodInvoker(org.junit.runners.model.FrameworkMethod method, Object testClass)` - **Returns**: `org.junit.runners.model.Statement` - **Description**: Returns a `InvokeParameterisedMethod` for parameterised methods and null for non-parameterised methods. ``` -------------------------------- ### Parameters Annotation with String Array Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/Parameters.html Use the 'value' element to define parameter sets as a String array. Each element represents a full parameter set, comma-separated. Values must match method parameters in order and type. ```java @Parameters({ "1, joe, 26.4, true", "2, angie, 37.2, false"}) ``` -------------------------------- ### TestMethod Methods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/internal/TestMethod.html Lists and describes the available methods for the TestMethod class. ```APIDOC ## Methods ### annotations * **Returns**: Annotation[] - An array of annotations present on the test method. ### equals * **Parameters**: * **obj** (Object) - The object to compare with. * **Returns**: boolean - True if the objects are equal, false otherwise. ### frameworkMethod * **Returns**: org.junit.runners.model.FrameworkMethod - The underlying JUnit FrameworkMethod. ### hashCode * **Returns**: int - The hash code value for this object. ### isIgnored * **Returns**: boolean - True if the test method is ignored, false otherwise. ### isNotIgnored * **Returns**: boolean - True if the test method is not ignored, false otherwise. ### isParameterised * **Returns**: boolean - True if the test method is parameterised, false otherwise. ### listFrom * **Static Method** * **Description**: Creates a list of `TestMethod` instances from a list of `FrameworkMethod` objects. * **Parameters**: * **annotatedMethods** (List) - A list of annotated methods. * **testClass** (org.junit.runners.model.TestClass) - The test class. * **Returns**: List - A list of `TestMethod` objects. ### name * **Returns**: String - The name of the test method. ``` -------------------------------- ### InvokeParameterisedMethod Methods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/internal/InvokeParameterisedMethod.html Documentation for the methods available in the InvokeParameterisedMethod class. ```APIDOC ## InvokeParameterisedMethod Methods ### getParamsAsString #### Description Returns a string representation of the parameters. #### Method GET #### Endpoint N/A (Instance method) #### Response * **String** - A string representation of the parameters. ``` ```APIDOC ## InvokeParameterisedMethod Methods ### evaluate #### Description Evaluates the test method with the provided parameters. This method is specified by the Statement class in JUnit. #### Method N/A (Abstract method implementation) #### Endpoint N/A (Instance method) #### Throws * **Throwable** - If an error occurs during evaluation. ``` -------------------------------- ### InvokeParameterisedMethod Constructor Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/internal/InvokeParameterisedMethod.html Details of the constructor for the InvokeParameterisedMethod class. ```APIDOC ## InvokeParameterisedMethod Constructor ### Description Initializes a new instance of the InvokeParameterisedMethod class. ### Method InvokeParameterisedMethod ### Parameters * **testMethod** (org.junit.runners.model.FrameworkMethod) - The framework method being tested. * **testClass** (Object) - The test class instance. * **params** (Object) - The parameters for the test method. * **paramSetIdx** (int) - The index of the parameter set. ``` -------------------------------- ### Override Initialization and Execution Methods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Methods inherited from BlockJUnit4ClassRunner for managing test lifecycle and method execution. ```java protected void collectInitializationErrors(List errors) ``` ```java protected void runChild(org.junit.runners.model.FrameworkMethod method, org.junit.runner.notification.RunNotifier notifier) ``` ```java protected List computeTestMethods() ``` ```java protected org.junit.runners.model.Statement methodInvoker(org.junit.runners.model.FrameworkMethod method, Object test) ``` -------------------------------- ### Converters and Exceptions Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/index-all.html Details on parameter converters and related exceptions. ```APIDOC ## Converters and Exceptions ### `junitparams.converters.ConversionFailedException` #### Constructor - **`ConversionFailedException(String)`**: Constructs a new `ConversionFailedException` with the specified detail message. ### `junitparams.converters.ParamConverter` #### `convert(Object, String)` - **Description**: Converts a parameter value to the expected type. - **Method**: Instance method - **Interface**: `junitparams.converters.ParamConverter` ### `junitparams.converters.ConvertParam` #### Description - **Annotation Type**: `junitparams.converters.ConvertParam` - **Purpose**: Defines a converter which should be used to convert a parameter to its expected type. ``` -------------------------------- ### Compute test methods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Retrieves the list of test methods to be executed. ```java computeTestMethods() ``` -------------------------------- ### Utils Class Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/index-all.html Utility class for JUnitParams. ```APIDOC ## Utils Class ### Description Utility class containing helper methods and constants for JUnitParams. ### Static Variables - **REGEX_ALL_NEWLINES**: A regular expression to match all newlines. ``` -------------------------------- ### ParameterisedTestMethodRunner Constructor Details Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/ParameterisedTestMethodRunner.html Details the constructor of the ParameterisedTestMethodRunner class. ```APIDOC ### Constructor Detail ### ParameterisedTestMethodRunner public **ParameterisedTestMethodRunner**([TestMethod](../junitparams/TestMethod.html "class in junitparams") testMethod) ``` -------------------------------- ### ParameterisedTestClassRunner Methods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/internal/class-use/TestMethod.html Methods for running parameterised tests within the ParameterisedTestClassRunner. ```APIDOC ## ParameterisedTestClassRunner.runParameterisedTest ### Description Executes a parameterised test method. ### Method void ### Endpoint ParameterisedTestClassRunner.runParameterisedTest(TestMethod method, Statement methodInvoker, RunNotifier notifier) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` ```APIDOC ## ParameterisedTestClassRunner.shouldRun ### Description Determines if a test method should be run by this runner. ### Method boolean ### Endpoint ParameterisedTestClassRunner.shouldRun(TestMethod testMethod) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **boolean** - True if the method should be run, false otherwise. #### Response Example None ``` -------------------------------- ### Load parameters from CSV files Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Use @FileParameters to load test data directly from a CSV file. ```java @Test @FileParameters("cartoon-characters.csv") public void shouldSurviveInJungle(int yearsInJungle, String person) { ... } ``` -------------------------------- ### runParameterisedTest Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/ParameterisedTestClassRunner.html Executes a parameterised test method. ```APIDOC ## runParameterisedTest ### Description Executes a parameterised method. ### Parameters - **method** (TestMethod) - Required - The test method to execute. - **methodInvoker** (Statement) - Required - The statement to invoke the method. - **notifier** (RunNotifier) - Required - The JUnit run notifier. ``` -------------------------------- ### runParameterisedTest Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/ParameterisedTestClassRunner.html Executes a parameterised test method. ```APIDOC ## runParameterisedTest ### Description Executes parameterised method. ### Parameters - **method** (TestMethod) - Required - The test method - **methodInvoker** (Statement) - Required - The method invoker - **notifier** (RunNotifier) - Required - The run notifier ``` -------------------------------- ### ParameterisedTestClassRunner Fields Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/ParameterisedTestClassRunner.html Details the fields available in the ParameterisedTestClassRunner class. ```APIDOC ## Fields ### `parameterisedMethods` - **Type**: `Map` - **Description**: Stores parameterised methods and their corresponding runners. ### `testMethods` - **Type**: `Map` - **Description**: Maps framework methods to TestMethod objects. ### `testMethodsList` - **Type**: `List` - **Description**: A list containing TestMethod objects. ``` -------------------------------- ### Parameterize tests via provider method Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Use a private method to return a collection of parameters for more complex test scenarios. ```java @Test @Parameters(method = "cartoonCharacters") public void cartoonCharacters(int yearsInJungle, String person) { ... } private Object[] cartoonCharacters() { return $( $(0, "Tarzan"), $(20, "Jane") ); } ``` -------------------------------- ### Initialize JUnitParamsRunner Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Constructor for the runner, requiring the test class to be initialized. ```java public JUnitParamsRunner(Class klass) throws org.junit.runners.model.InitializationError ``` -------------------------------- ### Internal Classes and Methods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/index-all.html Documentation for internal classes and their methods used within JUnitParams. ```APIDOC ## Internal Classes and Methods ### `junitparams.internal.TestMethod` #### `annotations()` - **Description**: Retrieves annotations associated with a test method. - **Method**: Instance method ### `junitparams.internal.ParameterisedTestClassRunner` #### `computeFrameworkMethods()` - **Description**: Returns a list of `FrameworkMethod`s. - **Method**: Instance method #### `computeTestMethods(TestClass)` - **Description**: Computes test methods for a given test class. - **Method**: Instance method ### `junitparams.internal.ParameterisedTestMethodRunner` #### `count()` - **Description**: Counts the number of parameterized test cases. - **Method**: Instance method ``` -------------------------------- ### describeParameterisedMethod Method Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/index-all.html Provides a description for a parameterised test method. ```APIDOC ## describeParameterisedMethod Method ### Description This method returns a textual description of a parameterised test method. It is used internally by the runner to provide information about the test. ### Method junitparams.internal.ParameterisedTestRunner.describeParameterisedMethod(FrameworkMethod) ### Parameters - **frameworkMethod** (FrameworkMethod) - Description: The framework method to describe. ``` -------------------------------- ### Using Excel File for Test Parameters Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Annotate your test method with @FileParameters to specify an Excel file and a custom mapper for data loading. The file path is relative to the test execution directory. ```java @Test @FileParameters(value = "cartoon-characters.xsl", mapper = ExcelCartoonMapper.class) public void shouldSurviveInJungle(Person person) { ... } ``` -------------------------------- ### @Parameters Annotation Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/Parameters.html Configuration options for the @Parameters annotation to define test data sources. ```APIDOC ## @Parameters Annotation ### Description The @Parameters annotation is used to define test parameters for a test method and specify how to obtain them. ### Parameters #### Optional Elements - **value** (String[]) - Optional - Parameter values defined as a String array. Each element is a comma-separated parameter set. - **source** (Class) - Optional - Parameter values defined externally in a class. The class must have public static methods starting with 'provide' returning Object[]. - **method** (String) - Optional - Parameter values returned by a method within the test class. Multiple methods can be specified using a comma-separated string. ### Usage Example @Parameters({ "1, joe, 26.4, true", "2, angie, 37.2, false"}) @Parameters(source = PeopleProvider.class) @Parameters(method = "examplaryPeople") ``` -------------------------------- ### DataMapper Interface Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/index-all.html The DataMapper interface provides a method to map file contents to parameters. ```APIDOC ## DataMapper Interface ### Description Interface for mapping file contents to parameters. ### Methods - **map(Reader)**: Maps file contents to parameters. ``` -------------------------------- ### evaluate Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/InvokeParameterisedMethod.html Executes the evaluation of the test statement. ```APIDOC ## evaluate ### Description Evaluates the test statement. This method overrides the evaluate method from org.junit.runners.model.Statement. ### Throws - **Throwable** - Throws a Throwable if the evaluation fails. ``` -------------------------------- ### POST /junitparams/TestMethod/runParameterisedTest Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/class-use/TestMethod.html Executes a parameterised test method using the provided runner components. ```APIDOC ## POST /junitparams/TestMethod/runParameterisedTest ### Description Executes a parameterised test method. ### Method POST ### Endpoint /junitparams/ParameterisedTestClassRunner/runParameterisedTest ### Parameters #### Request Body - **method** (TestMethod) - Required - The test method to execute. - **methodInvoker** (org.junit.runners.model.Statement) - Required - The statement invoker. - **notifier** (org.junit.runner.notification.RunNotifier) - Required - The run notifier for test events. ### Response #### Success Response (200) - **void** (null) - Execution completed. ``` -------------------------------- ### Parameterize tests with specific external methods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Specify particular methods from an external class to provide parameters. ```java @Test @Parameters(source = CartoonCharactersProvider.class, method = "cinderellaCharacters,snowwhiteCharacters") public void testPrincesses(boolean isAPrincess, String characterName) { ... } ``` -------------------------------- ### Pass objects as parameters Source: https://github.com/pragmatists/junitparams/wiki/Quickstart Inject complex objects directly into the test method parameters. ```java @Test @Parameters public void isAdult(Person person, boolean valid) throws Exception { assertThat(person.isAdult(), is(valid)); } private Object[] parametersForIsAdult() { return new Object[]{ new Object[]{new Person(13), false}, new Object[]{new Person(17), false}, new Object[]{new Person(18), true}, new Object[]{new Person(22), true} }; } ``` -------------------------------- ### Retrieve Test Descriptions Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Methods for obtaining JUnit Description objects for the runner and individual methods. ```java public org.junit.runner.Description getDescription() ``` ```java protected org.junit.runner.Description describeMethod(org.junit.runners.model.FrameworkMethod method) ``` -------------------------------- ### JUnitParamsRunner Methods Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/index-all.html Details on methods available in the JUnitParamsRunner class, which is central to parameterizing JUnit tests. ```APIDOC ## JUnitParamsRunner ### Description Provides methods for running parameterized JUnit tests. ### Methods #### `$(Object...)` - **Description**: Shortcut for returning an array of objects. - **Method**: Static method - **Class**: `junitparams.JUnitParamsRunner` #### `collectInitializationErrors(List)` - **Description**: Collects initialization errors during test setup. - **Method**: Instance method - **Class**: `junitparams.JUnitParamsRunner` #### `computeTestMethods()` - **Description**: Computes the test methods to be executed. - **Method**: Instance method - **Class**: `junitparams.JUnitParamsRunner` #### `describeMethod(FrameworkMethod)` - **Description**: Describes a specific test method. - **Method**: Instance method - **Class**: `junitparams.JUnitParamsRunner` ``` -------------------------------- ### Custom DataMapper for Excel Files Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Implement a custom DataMapper to parse Excel files for parameterized tests. Ensure your mapper implements the DataMapper interface and handles file reading and parsing logic. ```java public class CartoonMapper implements DataMapper { @Override public Object[] map(Reader fileReader) { // ... } } ``` -------------------------------- ### getParamsAsString Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/InvokeParameterisedMethod.html Retrieves the parameters of the method as a string representation. ```APIDOC ## getParamsAsString ### Description Returns the parameters associated with the method as a String. ### Response - **Return Type** (String) - A string representation of the parameters. ``` -------------------------------- ### Run child test Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/JUnitParamsRunner.html Executes a single child test method. ```java runChild(org.junit.runners.model.FrameworkMethod method, org.junit.runner.notification.RunNotifier notifier) ``` -------------------------------- ### shouldRun Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/ParameterisedTestClassRunner.html Determines if a specific test method should be executed by this runner. ```APIDOC ## shouldRun ### Description Tells if method should be run by this runner. ### Parameters - **testMethod** (TestMethod) - Required - The test method to check. ### Response - **boolean** - Returns true if the method should be run, false otherwise. ``` -------------------------------- ### junitparams.mappers Class Hierarchy Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/junitparams/mappers/package-tree.html Provides an overview of the class hierarchy within the junitparams.mappers package, highlighting the relationship between DataMapper, CsvWithHeaderMapper, and IdentityMapper. ```APIDOC ## Class Hierarchy * java.lang.Object * junitparams.mappers.CsvWithHeaderMapper (implements junitparams.mappers.DataMapper) * junitparams.mappers.IdentityMapper (implements junitparams.mappers.DataMapper) ## Interface Hierarchy * junitparams.mappers.DataMapper ``` -------------------------------- ### JUnitParams Class Hierarchy Source: https://github.com/pragmatists/junitparams/blob/master/apidocs/overview-tree.html Provides an overview of the class hierarchy within the JUnitParams library, showing inheritance relationships. ```APIDOC ## Class Hierarchy (JUnitParams 1.0.3-SNAPSHOT API) ### Description This section details the class hierarchy for the JUnitParams library, illustrating the relationships between different classes and their inheritance from standard Java classes and JUnit classes. ### Classes * `java.lang.Object` * `junitparams.mappers.CsvWithHeaderMapper` (implements `junitparams.mappers.DataMapper`) * `junitparams.mappers.IdentityMapper` (implements `junitparams.mappers.DataMapper`) * `junitparams.internal.ParameterisedTestClassRunner` * `junitparams.internal.ParameterisedTestMethodRunner` * `org.junit.runner.Runner` (implements `org.junit.runner.Describable`) * `org.junit.runners.ParentRunner` (implements `org.junit.runner.manipulation.Filterable`, `org.junit.runner.manipulation.Sortable`) * `org.junit.runners.BlockJUnit4ClassRunner` * `junitparams.JUnitParamsRunner` * `org.junit.runners.model.Statement` * `junitparams.internal.InvokeParameterisedMethod` * `junitparams.internal.TestMethod` * `java.lang.Throwable` (implements `java.io.Serializable`) * `java.lang.Exception` * `junitparams.converters.ConversionFailedException` * `junitparams.internal.Utils` ### Interfaces * `junitparams.mappers.DataMapper` * `junitparams.converters.ParamConverter` ### Annotations * `junitparams.converters.ConvertParam` (implements `java.lang.annotation.Annotation`) * `junitparams.FileParameters` (implements `java.lang.annotation.Annotation`) * `junitparams.Parameters` (implements `java.lang.annotation.Annotation`) ```