Testing POST methods with WebTest to simulation error condition.

I started a new Grails project recently, and I found Canoo’s WebTest extremely easy to get working. I was even able to get Cobertura code coverage integrated to my WebTests. I found there where several error conditions that I did not test in my code. So I really wanted to simulate error POST method invocations with WebTest.
First I wanted to find a way to add arbitrary POST parameters. I accomplished this by creating the invocation like that would POST an ID of 99 when there is no record 99 in the database

    void testUpdateItemNotFound() {
        def post = "id=99&version=123"
        invoke( url: "http://localhost:8080/divr/contextConfig/update",
                method: 'POST',
                content: "${post}")

        verifyText(text: 'ContextConfig not found with id 99')
    }

This worked great

What I found is what Cobertura was able to measure my code coverage on my WebTests, so I was able to identify what error scenarios I did not cover in a test

Conclusion

Do not settle testing just the happy path in your application. I feel there is always more testing that can be done.

VN:F [1.9.1_1087]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.1_1087]
Rating: 0 (from 0 votes)
  • Share/Bookmark

This entry was posted on Thursday, March 18th, 2010 at 2:42 pm and is filed under Grails-Groovy, Java-JavaEE-J2EE. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Testing POST methods with WebTest to simulation error condition.”

  1. Adaptive Project Framework: Managing Complexity in the Face of … | DevBlogr Says:

    [...] Testing POST methods with WebTest to simulation error condition … [...]

Leave a Reply

You must be logged in to post a comment.