Skip to content

schauder/parameterizedTestsWithRules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parameterized Tests With Rules

Demos how parameterized test can be implemented using JUnit Rules without a custom TestRunner.

You can define Generators for creating all the parameters to use for the tests.

Inside the test you can access the current value of the parameter using the value() method of the rule.

There is one working example of a Generator, the ListGenerator which takes the List of parameters as an constructor argument.

Example usage looks like this:

public class SimpleExampleTest {

    @Rule
    public Generator<String> params = 
        new ListGenerator(asList("alpha", "beta", "gamma"));

    @Test
    public void testSomething() throws Exception {
        assertTrue(params.value().length() >= 4);
    }
}

I also blogged about it here: http://blog.schauderhaft.de/2012/12/16/writing-parameterized-tests-with-junit-rules/

About

Demos how parameterized test can be implemented using JUnit Rules without a custom TestRunner

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages