The first column is the account id , the second stores the current balance. If I pass the sql statement to executeQuery it works as expected. In the first test we simulate the case that the account id does not exist, i. The setUp method for this test case is defined as follows: Even though I was not able to retrieve the mocked result set. Check out the release for an example. For instance, if you are testing a servlet class that directly looks up and interacts with an EJB, the non-basic version may be useful to you.

Uploader: Yozshur
Date Added: 5 February 2014
File Size: 8.78 Mb
Operating Systems: Windows NT/2000/XP/2003/2003/7/8/10 MacOS 10/X
Downloads: 16835
Price: Free* [*Free Regsitration Required]

In this post, however, we will focus on the first kind of test: Provides the central runtime behavior of the framework. Of course there are much more mockrunjer that can be done.


Conclusion Hopefully this article has provided you with a useful introduction to the Mockrunner framework. This page provides a quick overview over the JDBC test framework.

You now have a complete unit test to exercise the DAO logic that can be run without the need for a container or database.

Although you can interact directly with the test modules, which may be necessary if you already have a standard base class from which your tests extend, it is often more convenient to have your test cases extend from one the framework’s TestCase adapters. It uses a table with the name account. Normal statements work as expected, too. The following table describes the purpose of each category and lists some examples of the corresponding classes found in the distribution.


Even though I was not able to retrieve the mocked result set. When databases are involved, people will probably quickly jump to writing integration tests, because all they have to do is create a little Derby, H2 or HSQLDB or other test database, and run a couple of data-setup queries prior to the actual test.

In particular, you’ll want to ensure the correct SQL is being executed, the data returned from the query is being properly mapped into the domain object, and you’ll want to ensure all JDBC resources are being properly released. Unit testing is an essential practice for anyone seeking to develop better-designed, higher quality software. By exploring the API, I came across methods that are specifically meant to be used with PreparedStatements instances that I was not aware about: The topic of mock objects is often a point of confusion for those new to test-driven development, so before diving into the details of Mockrunner, it would be best to make sure you have an understanding of what exactly is a mock object.

The next step is to configure the action’s input forward by using the setInput method of the MockActionMapping class. The connection is established, but I only get an empty result set. Though, for a PreparedStatement this should not be necessary. Avoiding inter-dependencies and at the same time, avoiding costly database setups is hard. This is a sample test database for MockFileDatabase Its syntax is inspired from H2’s test script files When this query is executed This will allow you to test your actions without the need to load the Mckrunner container or rely on bean definitions wired in Spring’s applicationContext.

A valid list of results was returned and mocjrunner to the request and the request was forwarded to the results page. Thankfully, mockrunnre core distribution ships with several useful examples of technologies not covered in this introduction as well as some further approaches to the topics already addressed. The importance of doing the right test-driven development is to find a good ratio of what kind of code is to be covered…. It can be used to transfer an amount of money from one account to another.


Contents What is a Mock Object? Obtaining a reference to this class can be done either by subclassing one of Spring’s Action extensions or by using its WebApplicationContextUtils class.

The first column is the account idthe second stores the current balance. I contacted the authors of mockrunner and the issue was resolved by the developers several month later: Finally, a quick examination of the HttpServletRequest is performed to ensure it was populated with the results of the query.

Maven Repository: nner » mockrunner-jdbc

It’s a simple and easy to use API, but can be a source of serious application problems if not written correctly. Despite the simplicity of the example, mockrunnfr still illustrates several concerns common to most JDBC code.

Mockrunner keeps track on every executed SQL statement. The expected output is mocckrunner resultset with “1” and “foobar”, as well as the SQL statement that is executed.