13. 用意されているテスト
●
Unit Tests
–Junitで各クラスを
●
Functional Tests
– Junit + HttpClient でコントローラを叩いて
●
Selenium Test
– ビルトインされたSelenium で受け入れテスト
14. Unit Test
import play.test.*;
import org.junit.*;
public class MyTest extends UnitTest {
@Test
public void aTest() {
assertEquals(2, 1 + 1); // A really important thing to test
}
@Test
public void testUsers() {
assertEquals(3, Users.count());
}
}
15. Functional Test
import play.test.*;
import play.mvc.*;
import play.mvc.Http.*;
import org.junit.*;
public class ApplicationTest extends FunctionalTest {
@Test
public void testTheHomePage() {
Response response = GET("/");
assertStatus(200, response);
}
}
16. Selenium Test
#{selenium 'Test security'}
// Try to log in the administration area
clearSession()
open('/admin')
assertTextPresent('Login')
type('login', 'admin')
type('password', 'secret')
clickAndWait('signin')
// Verify that the user in correctly logged in
assertText('success', 'Welcom admin!')
#{/selenium}
※直接HTMLテーブルを書く方法でもできます
33. HtmlUnitとは
●
HtmlUnit is a "GUI-Less browser for Java
programs". It models HTML documents and
provides an API that allows you to invoke
pages, fll out forms, click links, etc... just like
you do in your "normal" browser.
(http://htmlunit.sourceforge.net/)
●
Jenkins内部のHudsonTestCaseの中にも組み込ま
れてますよね