Skip to content

Commit

Permalink
add rules acceptance test for junit4/ (#22)
Browse files Browse the repository at this point in the history
* hint: only works for 4.9 <= junit < 5.0)

Signed-off-by: Andreas Schmid <[email protected]>
  • Loading branch information
aaschmid committed Jul 10, 2018
1 parent ce7ebd8 commit b4b93df
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.tngtech.test.java.junit.dataprovider;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runner.RunWith;

import com.tngtech.java.junit.dataprovider.DataProviderRunner;

@RunWith(DataProviderRunner.class)
public class RuleAcceptanceTest {

public static class SomeTestRule extends TestWatcher {
boolean started;

@Override
protected void starting(Description description) {
started = true;
}

@Override
protected void finished(Description description) {
assertThat(started).as("Rule was not started, but 'finished' called").isTrue();
}
}

@ClassRule
public static final SomeTestRule classRule = new SomeTestRule();

@Rule
public SomeTestRule rule = new SomeTestRule();

@Test
public void testClassRuleShouldBeStartedBeforeTest() {
// Expected:
assertThat(classRule.started).as("'@ClassRule' was not started").isTrue();
}

@Test
public void testRuleShouldBeStartedBeforeTest() {
// Expected:
assertThat(rule.started).as("'@Rule' was not started").isTrue();
}
}

0 comments on commit b4b93df

Please sign in to comment.