How do I write useful unit/integration tests when using Spring AOP and @Transactional?

If you write a test that is context aware you could get all aspects from the context and assert that the order is the intended.

If you write a test that is context aware you could get all aspects from the context and assert that the order is the intended. Another solution is to find any resource that could throw a duplicate key exception and just call it twice with the same value. At least the second call should log the exception.

You probably want to load your entire Spring context for the tests except for the DataSource. For the database stuff, take a look at MockRunner. It has a good set of mock JDBC classes.In your Spring context (maybe via a separate xml file), swap out your real DataSource with a MockDataSource for the test.

Retrieve this DataSource from the context in your test cases and you can do something like the following: MockResultSet rs = new MockResultSet("SELECT 1"); rs. AddRow(new Object { 1 }); MockConnection con = new MockConnection(); con. GetPreparedStatementResultSetHandler().

PrepareResultSet("SELECT 1", rs); PreparedStatement ps = connection. PrepareStatement("SELECT 1"); ps.executeQuery() Note that if you want to throw an exception, the result set handler (via AbstractResultSetHandler) has a prepareThrowsSQLException() which you can use to specify that a specific SQL string should throw an exception. Mix and match the above with @Before and @BeforeClass methods depending on what you need to setup before each test case.

Be aware that Mock JDBC Statements keep a record of all executed SQL, so if you are running a huge number of JDBC calls (millions? ), memory / performance could be an URL2 may be easiest to just create a new Connection / Statement for each test case. Finally, if you are using Maven, MockRunner pulls in a lot of other things you don't need for JDBC mocks.

Here's how I have it defined in the pom. Xml: com. Mockrunner mockrunner-jdk1.5-j2ee1.3 0.4 test xml-apis xml-apis cglib-nodep cglib-nodep jboss jboss-jee struts struts org.

Mockejb mockejb nekohtml nekohtml commons-validator commons-validator commons-digester commons-digester commons-beanutils commons-beanutils xerces xercesImpl jdom jdom javax. Servlet servlet-api.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions