Tests

Play 1.4.x

Test – Unit Tests

@Test public void getRental() { ... }
@Test (expected = NumberFormatException.class )
@Ignore
Ignore any errors

@Test (timeout=400)
Test will fail after 400 milliseconds

@Before public void prepareRecords();
Run before each unit test

@After public void cleanupJunk()
Run after each unit test

@BeforeClass void whenTestClassInstantiated();
Run once, when the test class gets instantiated

@AfterClass void whenTestClassCompleted()
Run once when the test class is dismissed

Assert.assert
There are tons of assertions, look it up

Test – Functional Tests

public class ApplicationTest extends FunctionalTest
Functional test are unit tests with an HTTP orientation

newRequest()
newResponse()
GET(request, url)
PUT(request, url)
POST(request,url)
DELETE(request,url)
assertStatus(404, response)
assertHeaderEquals(headerName, value, response)
assertContentEquals(content, response)
assertContentType(type,response)
clearCookies()

Test – Selenium Tests

#{selenium}
clearSession()
open(‘/admin’)
assertTextPresent(‘Login’)
type(‘login’, ‘admin’)
type(‘password’, ‘secret’)
clickAndWait(‘signin’)

// Verify that the user in correctly logged in
assertText(‘success’, ‘Welcome admin!’)
#{/selenium}

Test – Data loader

@Before public void setUp() { Fixtures.deleteAll();
Fixtures.loadModels("data.yml");}
Fixtures is used to initialise the datastore before running a unit test

#{fixture delete:'all', load:'data.yml' /} or #{fixture delete:'all', loadModels:'data.yml' /}
#{selenium} ... #{/selenium}
Same idea using a Selenium test(loadModels and load parameters are synonyms).