|
|
|
|
|
by latch
5205 days ago
|
|
This is the first controller I opened from their samples[1] : public class Forums extends Application {
public static void index() {
List forums = Forum.findAll();
long topicsCount = Topic.count();
long postsCount = Post.count();
render(forums, topicsCount, postsCount);
}
...
}
You can't mock out Forum, Topic or Post. You can't inject some type of "FormRepository" or whatever pattern you want to gain some type of control. In Ruby, or most dynamic languages, this wouldn't be a problem, since a class method can (and should) be mocked. Even if a static language allows for that sort of trickery (for example, there are a couple ways to test the above in C#), it's the wrong approach. Dependencies should be injected and thus controlled. I guess you could inject using static setters, but that's just a bad workaround to what, in my opinion, is a fundamental misunderstanding of how to write testable code.[1] https://github.com/playframework/play/blob/master/samples-an... |
|
[1] http://code.google.com/p/jmockit/