Last updated by admin 3 years ago
??????????? {excerpt:hidden=true}Functional Testing{excerpt}
{excerpt:hidden=true} In addition to unit testing, Grails supports functional testing of your web application.{excerpt}???????????Grails?????????????????????????????????{excerpt:hidden=true} For this purpose, it uses the free open-source
Canoo WebTest.{excerpt}
?????????????????
Canoo WebTest?????????????????????????? {excerpt:hidden=true}How to test your web application{excerpt}
????????? {excerpt:hidden=true}Install and create{excerpt}
{excerpt:hidden=true}From the root directory of your application call{excerpt} ????????????????????????????????grails create-webtest
- downloads Canoo WebTest if needed and installs under {{grails.home/downloads/webtest}}. The intial dowload can take a few minutes. The progress of download is indicated.
- creates the test directory structure for the current application
- creates standard properties and a standard test suite{excerpt}
- ????Canoo WebTest??????????{{grails.home/downloads/webtest}} ??????????????????????????????????????????????
- ?????????????test??????????????
- ?????????test suite??????
grails generate-webtest
- creates an initial webtest for the default views and controllers of the domain class
- tests basic operations: list, create, delete through the web GUI
- ?????????????????????????????webtest???
- web GUI?????????????: list, create, delete ????
?????? {excerpt:hidden=true}Running the tests{excerpt}
{excerpt:hidden=true} From the root directory of your application call{excerpt} ????????????????????????????grails run-webtest
?????? {excerpt:hidden=true}Defining your tests{excerpt}
Webtest??????????? {excerpt:hidden=true}The webtest folder layout{excerpt}
{excerpt:hidden=true} After creation and generation of a test for the {{mydomain}} domain class, you'll find the following files and folders below your application folder:{excerpt} ????????(grails create-webtest)? {{mydomain}} ????????????????(grails generate-webtest)?????????????????????????????????????????????:myapp
+-- webtest
+-- conf (webtest.properties)
+-- reports (readme.txt)
+-- tests (TestSuite.groovy, MydomainTest.groovy)?????????? {excerpt:hidden=true}Adapting the test logic{excerpt}
{excerpt:hidden=true} MydomainTest.groovy will initially contain lines like{excerpt} MydomainTest.groovy????????????????????class MydomainTest extends grails.util.WebTest { // ????????????????????????????????????? // ??????????????? void suite() { testMydomainListNewDelete() // ??????????????? } def testMydomainListNewDelete() { webtest('Mydomain basic operations: view list, create new entry, back to view, delete, view'){ invoke(url:'mydomain') verifyText(text:'Home') verifyListPage(0) // <- ??????????????????????? clickLink(label:'New Mydomain') verifyText(text:'Create Mydomain') clickButton(label:'Create') // more … }
??????? {excerpt:hidden=true}More Tests{excerpt}
{excerpt:hidden=true} You can have many tests like MydomainTest.groovy in the {{tests}} directory or its subdirectories.{excerpt} {{tests}} ?????????????????????MydomainTest.groovy????????????????{excerpt:hidden=true} Every such test must extend {{grails.util.WebTest}} and provide a {{suite}} method that calls each available test method. In subdirectories, tests must have the according package statements. {excerpt} ??????????????{{grails.util.WebTest}} ?extend????????????????????? {{suite}} ?????????????????? {excerpt:hidden=true} Tests will automatically be picked up by TestSuite.groovy. You can customize this logic to define your own suite (see its inlined comments on how to do that). {excerpt} ????TestSuite.groovy??????????????????????suite??????????????????????????????(?????????????????)? {excerpt:hidden=true} Customization of the suite is sometimes needed to assert a special sequence of test execution or to restrict the test execution to a subset of availabable tests. {excerpt} suite???????????????????????????????????????????????????????????????????-
null
null
null
null
null
- testing nullnullnullnullnull



