Using Spring dependencies in your acceptance tests with Thucydides
Introducing Thucydides
Thucydides on Github
Thucydides on Java.net
Presentations
Releases
Tips and Tricks
Tutorials
If you are running your acceptance tests against an embedded web server (for example, using Jetty), it can occasionally be useful to access the service layers directly for fixture or infrastructure-related code. For example, you may have a scenario where a user action must, as a side effect, record an audit log in a table in the database. To keep your test focused and simple, you may want to call the service layer directly to check the audit logs, rather than logging on as an administrator and navigating to the audit logs screen.
Spring provides excellent support for integration tests, via the SpringJUnit4ClassRunner test runner. Unfortunately, if you are using Thucydides, this is not an option, as a test cannot have two runners at the same time. Fortunately, however, there is a solution! To inject dependencies using a Spring configuration file, you just need to include the Thucydides SpringIntegration rule in your test class. You instantiate this variable as shown here:
Then you use the @ContextConfiguration annotation to define the configuration file or files to use. The you can inject dependencies as you would with an ordinary Spring integration test, using the usual Spring annotations such as @Autowired or @Resource. For example, suppose we are using the following Spring configuration file, called ‘config.xml’:
We can use this configuration file to inject dependencies as shown here:
Other context-related annotations such as @DirtiesContext will also work as they would in a traditional Spring Integration test. Spring will create a new ApplicationContext for each test, but it will use a single ApplicationContext for all of the methods in your test. If one of your tests modifies an object in the ApplicationContext, you may want to tell Spring so that it can reset the context for the next test. You do this using the @DirtiesContext annotation. In the following test case, for example, the tests will fail without the @DirtiesContext annotation:
Digg
Acceptance Testing with Thucydide and Spring
Thucydides Release 0.4.10 – Spring Integration | Official Thucydides Web Test Blog
Fill in your details below or click an icon to log in:
Please log in to WordPress.com to post a comment to your blog.
You are commenting using your Twitter account. ( Log Out / Change )
You are commenting using your Facebook account. ( Log Out / Change )
Connecting to %s
Notify me of follow-up comments via email.
Note: HTML is allowed. Your email address will never be published.
Subscribe to comments
Search
Blogroll Official Selenium Blog Thucydides on Github Thucydides User Manual Wakaleo Consulting – The Thucydides Company
Official Selenium Blog
Thucydides User Manual
Wakaleo Consulting – The Thucydides Company
Archives December 2011 (2) November 2011 (1) October 2011 (5) September 2011 (7)
December 2011 (2)
November 2011 (1)
October 2011 (5)
September 2011 (7)
Tags ATDD BDD easyb firefox Java jenkins jira JUnit parallel testing reporting screenshots selenium spring Thucydides
Follow Blog via Email Enter your email address to follow this blog and receive notifications of new posts by email.
Enter your email address to follow this blog and receive notifications of new posts by email.
About This is the official blog for the Thucydides automated acceptance testing library. It contains news and updates about Thucydides releases, as well as tips, tricks and tutorials on how to use Thucydides to improve your WebDriver-based web tests, and links to related material.
Pages Introducing Thucydides Thucydides on Github Thucydides on Java.net
Blog at WordPress.com .
Theme: Traction by The Theme Foundry
Get every new post delivered to your Inbox.
Join 1,710 other followers