junit-team / junit4

A programmer-oriented testing framework for Java.
https://junit.org/junit4
Eclipse Public License 1.0
8.52k stars 3.26k forks source link

`@FromDataPoints("misspelled") EnumType` shouldn't test all enum values #1648

Open awturner opened 4 years ago

awturner commented 4 years ago
@RunWith(Theories.class)
public class NonExistentTheory {
  @DataPoints("foo")
  public static final ImmutableSet<MetaSyntacticVariable> FOOS =
      ImmutableSet.of(MetaSyntacticVariable.FOO);

  @Theory
  public void doWithTheFoo(@FromDataPoints("bar") MetaSyntacticVariable whatever) {
    System.err.println(whatever);
  }

  @Theory
  public void doWithTheBoolean(@FromDataPoints("bar") boolean whatever) {
    System.err.println(whatever);
  }

  enum MetaSyntacticVariable {
    FOO, BAR, BAZ
  }
}

It is surprising that these @FromDataPoints-annotated parameters receive the same values as if the annotation were omitted. This means that typos in data point names aren't flagged as errors.

If the @FromDataPoints is present, and nothing matches, it would be helpful to raise "Never found parameters that satisfied method assumptions.".

awturner commented 4 years ago

Ping?

VivekShahare04 commented 2 months ago

To ensure that the @FromDataPoints annotation correctly enforces that data points are used as specified and raises an error if there are no matching data points, you can use JUnit's Assume class. This will help ensure that if the specific data points are not provided, the tests will fail with a clear message. @awturner

1.import org.junit.Assume; 2.Use Assume.assumeTrue to check if the data points are available before running the tests.

@awturner could you assign me this i'll just try to bebug it?