playframework/playframework — pull request #2720 by julienrf (2014-04-28 13:10:59+00:00)
Title: [java] play.test.With* helper classes should automatically call `start()` before each test

Currently the [`play.test.WithApplication`](https://github.com/playframework/playframework/blob/master/framework/src/play-test/src/main/java/play/test/WithApplication.java), [`play.test.WithServer`](https://github.com/playframework/playframework/blob/master/framework/src/play-test/src/main/java/play/test/WithServer.java) and [`play.test.WithBrowser`](https://github.com/playframework/playframework/blob/master/framework/src/play-test/src/main/java/play/test/WithBrowser.java) classes all define an `@After` method automatically stopping, after each test, the eventually started application or server.

However, none define a similar `@Before` method starting the application or server before each test. It means that users have to start them manually (or write their own `@Before` method) by invoking a `start` method. I guess this is because the `start` method takes parameters (see [here](https://github.com/playframework/playframework/blob/master/framework/src/play-test/src/main/java/play/test/WithServer.java#L26) and [there](https://github.com/playframework/playframework/blob/master/framework/src/play-test/src/main/java/play/test/WithApplication.java#L19)) and fixing these parameter values in a `@Before` method is not desired (we want the user to be able to fix this values).

I suggest to trade these parameters for methods so that they can always be overridden by users and they make it possible to define the `@Before` set up method:

```java
public class WithApplication {

protected FakeApplication app;

// Default application implementation, overridable by users
protected FakeApplication getApplication() {
return Helpers.fakeApplication();
};

@Before
public void start() {
app = getApplication();
Helpers.start(app);
}

@After
public void stopPlay() {
if (app != null) {
Helpers.stop(app);
app = null;
}
}

}
```

Same for `WithServer` and `WithBrowser`.

What do you think?