-
Notifications
You must be signed in to change notification settings - Fork 0
Testing
pramode edited this page Jun 29, 2011
·
4 revisions
Under the folder "test", create MyTest.java:
import play.test.*;
import org.junit.*;
import models.*;
public class MyTest extends UnitTest {
@Test
public void aTest() {
assertEquals(2, 1 + 1); // A really important thing to test
}
@Test
public void testUsers() {
assertEquals(2, Client.count());
}
}
Run the test:
play test playapp
Create the file MyFunctionalTest.java:
import play.test.*;
import play.mvc.*;
import play.mvc.Http.*;
import org.junit.*;
public class MyFunctionalTest extends FunctionalTest {
@Test
public void testTheHomePage() {
Response response = GET("/foo");
assertStatus(200, response);
}
}
Have a function like this in your test class:
@Before
public void setUp() {
Fixtures.deleteAll();
}
Create a .yml file (say data.yml) under the test folder:
Client(Ramu):
name: Ramu
age: 35
Client(Gopu):
name: Gopu
age: 30
Client(Asok):
name: Asok
age: 45
And, call the function Fixtures.loadModels("data.yml"):
@Before
public void setUp()
{
Fixtures.deleteAll();
Fixtures.loadModels("data.yml");
}