Created
October 19, 2012 11:31
-
-
Save bverbeken/3917715 to your computer and use it in GitHub Desktop.
Custom JUnit runner for Playframework (2.0) apps to eliminate boilerplate code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(PlayJUnitRunner.class) | |
public class AfterOrganisationTest { | |
@Test | |
public void canBePersisted() { | |
new Organisation("org1").save(); | |
Organisation reloadedOrg = Ebean.find(Organisation.class).findUnique(); | |
assertThat(reloadedOrg.name).isEqualTo("org1"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static play.test.Helpers.*; | |
public class BeforeOrganisationTest { | |
@Test | |
public void aTestInAnApplication() { | |
running(fakeApplication(inMemoryDatabase()), new Runnable() { | |
@Override | |
public void run() { | |
new Organisation("org1").save(); | |
Organisation reloadedOrg = Ebean.find(Organisation.class).findUnique(); | |
assertThat(reloadedOrg.name).isEqualTo("org1"); | |
} | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.runner.notification.RunNotifier; | |
import org.junit.runners.BlockJUnit4ClassRunner; | |
import org.junit.runners.model.InitializationError; | |
import play.test.FakeApplication; | |
import static play.test.Helpers.*; | |
public class PlayJUnitRunner extends BlockJUnit4ClassRunner { | |
public PlayJUnitRunner(Class<?> clazz) throws InitializationError { | |
super(clazz); | |
} | |
public void run(final RunNotifier notifier) { | |
FakeApplication app = fakeApplication(inMemoryDatabase()); | |
start(app); | |
super.run(notifier); | |
stop(app); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment