Craig, It depends on how you run the tests.
If you are using JUnit annotations (@RunsWith(SpringJUnit4ClassRunner)), then you need to run with JUnit. If you are running with JBehave - then it runs the embedder on its own. It will not use that JUnit annotation. There are JBehave annotations for that. Also when you mark the Steps class as @Transactional, Spring will create a proxy and the @Given/@When/@Then annotated methods are not found anymore on the proxy. A couple of folks have asked about that. It might depend on how you weave the class (AspectJ vs Spring-AOP). Also, I don't get your setup. Your Services should be @Transactional. Your Steps classes are clients to those services. If you make the steps transactional and they rollback, then you won't have data for your Thens. no? And making your Stories class @Transactional makes me think that you will run the whole suite as a transaction which could be huge transaction log at the database level and hugely slow. Stories / Steps should be clients to the system under test including its transactional logic. Brian ----- Original message ----- From: "Craig Tataryn" <[email protected]> To: [email protected] Date: Mon, 6 Feb 2012 16:05:53 +0000 (UTC) Subject: [jbehave-user] Re: JBehave and Spring Transactions... Carlus Henry <carlushenry@...> writes: > > > Brian.... > > Thanks once again. I will look into the TransactionalTestExecutionListener. You also make valid points about using a fresh database and examining the resource strategy as well. > > Thanks again... > > On Mon, Jan 3, 2011 at 3:30 PM, Brian Repko <brian.repko- [email protected]> wrote: > > > > Carlus, > > Look at Spring's org.springframework.test.context.transaction.TransactionalTestExecutionListenerI 'm not sure that you need to do the <at> BeforeTransaction / <at> AfterTransaction logic - perhaps > you would - but that code should be the basis of your code - the beforeTestMethod and > afterTestMethod should be like BeforeScenario and AfterScenario. > > I'm assuming that you'll always rollback. > > In terms of the resource setup strategy - I get that that might be a limitation - but you > shouldn't be running tests against real data - how can you guarentee your regression testing > isn't failing based on bad data? The use of another database - setup from scratch however > you do that - is highly recommended for acceptance testing. That's why DbFIT is so popular > for FIT testing. > > B > I'm having a very similar problem and I just can't figure out how to get my Spring transactions working across all my steps. My situation is this: * I have a Stories class which uses a SpringJUnit4ClassRunner: https://gist.github.com/1752773 * The embedder class looks like so: https://gist.github.com/1752899 * I have a Steps class which inserts some data into a table via a JdbcTemplate and uses my Service class to read back the data using JPA: https://gist.github.com/1752795 The Stories class has been marked @Transactional(readOnly = false). The problem I'm having is, there doesn't seem to be a Transaction present when it comes time to execute my service code to retrieve player info and thus it doesn't participate in the same transaction as the JdbcTemplate INSERTS. I can even put a call to my retrieval service right below JdbcTemplate INSERT statements and still it can't find the records inserted into the database. Has anyone else run into a similar situation and if so, how did you fix it? Thanks, any help/guidance would be greatly appreciated. Craig. P.S. On a strange note: if I annotate my Steps class with @Transactional, all my steps get reported as "PENDING", essentially in the eyes of jBehave they disappear... --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
