Return-Path: X-Original-To: apmail-struts-user-archive@www.apache.org Delivered-To: apmail-struts-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C05CB6282 for ; Fri, 20 May 2011 09:38:43 +0000 (UTC) Received: (qmail 26835 invoked by uid 500); 20 May 2011 09:38:41 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 26811 invoked by uid 500); 20 May 2011 09:38:41 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 26803 invoked by uid 99); 20 May 2011 09:38:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 May 2011 09:38:41 +0000 X-ASF-Spam-Status: No, hits=2.9 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [212.113.174.24] (HELO mx.netcabo.pt) (212.113.174.24) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 May 2011 09:38:31 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAJk11k1RVHir/2dsb2JhbACEXaE9eIhwqnuRCYUSgQcElECKRw Received: from a81-84-120-171.cpe.netcabo.pt (HELO mail.almeida.at) ([81.84.120.171]) by neti05smtpa.hdi.tvcabo with ESMTP; 20 May 2011 10:38:09 +0100 Received: from localhost (localhost [127.0.0.1]) by mail.almeida.at (Postfix) with ESMTP id 7110F2D90D for ; Fri, 20 May 2011 10:38:09 +0100 (WEST) X-Virus-Scanned: Debian amavisd-new at almeida.at Received: from mail.almeida.at ([127.0.0.1]) by localhost (mail.almeida.at [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5ZJSeeYMeg6x for ; Fri, 20 May 2011 10:38:07 +0100 (WEST) Received: from [192.168.10.111] (bl9-148-5.dsl.telepac.pt [85.242.148.5]) by mail.almeida.at (Postfix) with ESMTPA id 2717C2D649 for ; Fri, 20 May 2011 10:38:07 +0100 (WEST) Subject: Re: S2 TEst Best Practices From: Miguel To: Struts Users Mailing List In-Reply-To: References: Content-Type: multipart/alternative; boundary="=-smlKp7CJjUUFNCsqAXjx" Date: Fri, 20 May 2011 10:38:06 +0100 Message-ID: <1305884286.1959.104.camel@itcd001> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 X-Virus-Checked: Checked by ClamAV on apache.org --=-smlKp7CJjUUFNCsqAXjx Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Hi Frans, On Fri, 2011-05-20 at 14:52 +0700, Frans Thamura wrote: > > and i have several question, and i think that is good if we can share it here > > i want to know, the test mechanisme , best practices of testing in Struts2 world > I work in TDD, which means I write the tests first and then develop the functionality (check Lasse Koskela's book on the subject). My usual methodology is: - Pick up a story/use case (eg: click on People list button shows the list of all people in the phone book list) - Write a Test class for the PeopleAction.list() method - There will be a couple of tests: happy path, what if there aren't any people, what if there's a problem accessing the database? - Recently I've been developing a lot with services. this means the action will usually be simple, something like manipulate the properties that come from the request (if necessary) and pass them to the service - The last sentence means I can mock up the service here: I am interested in testing if the action behaves correctly - ie, if it catches exceptions, sends to the correct result, I am not really interested in knowing if the database is being accessed correctly. So EasyMock is a good library to use - After building the test and the Action, I do have the problem: is my service (eg service.getAllPeople() ) working as expected? Time for some integration test. Bare in mind I'm working in TDD: I've build an interface for the service, but the implementation doesn't exist yet - I repeat the test-build cycle, this time to build the correct implementation of service.getAllPeople(). - Work done Now, some remarks: - This unit testing doesn't do struts integration, such as: - Struts validation - My custom authorisation (I have developed a @AuthorisedRoles annotation that only authorised users with some roles to execute that action I'm not really sure what/when/where is the best way to test this. Right now I test this in a separate class that I suffix with, eg, *ValidationIntegrationTest. I'm not 100% happy with this approach, as a) I end up testing my action in 2 or 3 different places b) I'm not completely happy with my validation test class yet, which currently extends from StrutsSpringTestCase Regards, Miguel Almeida --=-smlKp7CJjUUFNCsqAXjx--