Slim3のUnitテスト

Slim3のプロジェクトについてるbuild.xmlを使ってmodel, service, controllerを生成すれば自動生成できるけど、Utilityクラスなど自分で作ったクラスに対するテストケースを作る場合のためのメモ

Controller

  • ControllerTestCaseを継承する
    • Datastore, MemcacheAPIが使えるようになる
    • tester変数を使ってブラウザテスト的なことができる
import org.slim3.tester.ControllerTestCase;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

public class MyControllerTest extends ControllerTestCase {
//[...]
}

それ以外

  • AppEngineTestCaseを継承する
    • Datastore, MemcacheAPIが使えるようになる
import org.slim3.tester.AppEngineTestCase;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

public class MyServiceTest extends AppEngineTestCase {
//[...]
}