Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JUnit 5 Theories #1415

Closed
wants to merge 103 commits into from
Closed

JUnit 5 Theories #1415

wants to merge 103 commits into from

Conversation

nrllewellyn
Copy link

@nrllewellyn nrllewellyn commented May 11, 2018

Overview

Adds theories, in a form similar to JUnit 4's Theories. This will close ticket #395.

Substantial changes from JUnit 4:

  • Methods allowed as sources of data points
  • Streams and Iterators as accepted data point types, but only when produced by methods (since both are stateful, they have to come from a method so they can be read more than once)
  • Suppliers system for simple data points (similar in form to parameterized tests, but allows mixing of in-line data points with class-level data points)
    • Specified via the ArgumentsSuppliedBy meta-annotation. This ties the annotation to a supplier class
    • Supplier class implements TheoryArgumentSupplier (or extends AbstractTheoryArgumentSupplier for common use cases). This class reads the annotation and produces the corresponding data points
    • Examples:
@Theory
public void myTheory(@IntValues(0, 42, 99) int someIntValue)

@Theory
public void myTheory(@ByteValues(0, 42) byte somByteValue, SomeClass valueFromClassLevelDataPoint)
  • Qualifiers directly on theory parameters. Example:
@DataPoints(qualifiers = "nonZero")
private static final List<Double> GREATER_THAN_ZERO = Arrays.asList(3, 5, 7);

@DataPoint
private static final Double ZERO = 0;

@DataPoint(qualifiers = "nonZero")
private static final double NEGATIVE_NUMBER =  -4;

@Theory
public void testDivisionOperator(double dividend, @Qualifiers("nonZero") double divisor)

A few (very rough) examples can be found in:
junit-jupiter-theories/src/test/java/org/junit/jupiter/theories/TheoriesTestCase.java


I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

nrllewellyn and others added 30 commits May 11, 2018 02:40
This version is missing tests and may need to have TheoryParam removed
before the final version, but it adds the basic functionality and
layout.
TheoryParam removed due to no longer being necessary. Well-known type
support encapsulated for ease of maintenance.
Removes the need to pass and implied reference to "this" inside the
constructor of TheoryInvocationContext when creating the failure message
fixer.
Also includes misc cleanup for tests.
These aren't needed, since annotations can't have null values
Removes the need to pass and implied reference to "this" inside the
constructor of TheoryInvocationContext when creating the failure message
fixer.
Also includes misc cleanup for tests.
These aren't needed, since annotations can't have null values
# Conflicts:
#	junit-jupiter-theories/junit-jupiter-theories.gradle
@nrllewellyn
Copy link
Author

PR change list seems to have been corrupted during a rebase (probably user error on my part). Closing and re-opening PR to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants