On Today at 1:19pm, GL=>Greg Lindholm <greg.lindh...@gmail.com> wrote:
GL> Well everyone has an opinion so here mine: GL> GL> I want to unit test my Struts actions in the full Struts context which GL> includes the interceptor stack and validation. This way I know my GL> actions and results are configured correctly since I test them. I also GL> know my declarative validations are working correctly. I use junit and GL> I really don't want or have time to have to learn another test tool GL> for integration testing. GL> Hi, +1. I'm biased in my opinion though. I helped write part of the code that's being quoted on: http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/ We like to test against the complete struts context include the relevant interceptor stack. This gives us the ability to test for all kinds of combinations of compelte and partially incomplete input. We like to test with mock database layer (for speed purposes). E.g., when providing incomplete input, I can test for: assertEquals(INPUT, proxy.execute()); assertEquals("4 field errors", 4, action.getFieldErrors().size()); In addition, we also like to test out the rendered result, all while running the ActionTest. It helps catch fat-finger mistakes. E.g, we can write code like to check that our freemarker template got rendered properly: assertTrue("Content contains first record", content.contains("{'institutionType.type': 'CEC'}")); assertTrue("Content contains last record", content.contains("{'institutionType.type': 'COL'}")); assertEquals("Number of records in list should be 4", 4, StringUtils.countMatches(content, "'institutionType.type':")); GL> GL> So to do this type of testing I wrote a StrutsTestContext class to run my GL> actions. GL> For full info see: GL> http://glindholm.wordpress.com/2008/06/30/unit-testing-struts-2-actions/ GL> I glanced briefly at the provided code on Greg's and it looks similar in principle to the depressedprogrammer (arsenalist) code. Good work, Greg. GL> GL> I don't use Spring so this class would need to be tweaked for Spring but you GL> are welcome to use this as a starting point. GL> GL> This gives me a lot of flexibility for testing, sometimes I test GL> against an actual database (with hibernate) and sometimes I mock the GL> services that the actions use. GL> Later, -- Haroon Rafique <haroon.rafi...@utoronto.ca> --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org