JUnit Tests in OFBiz – Data Setup and Execution

Mridul PathakPublished: Updated:

 

Yesterday I was discussing some JUnit designs with my colleagues and we came across one of my old mailing list discussions (Preparing Test Data for JUnit Tests) with Apache OFBiz cofounder David E. Jones around data setup best practices for manual and automated testing where he said:

Data that we use for demonstration and manual tests is just as good for automated tests, and for the most part the reverse is true i.e. data good for automated tests is also good for demonstration and manual tests. – David E. Jones

Instantly we came up with the idea to write a blog on this topic.

Unit testing is a key aspect of software development and the quality assurance process. When it comes to enterprise scale software solutions, unit tests act as building blocks for detailed testing requirements of integration and system testing.

OFBiz has robust support for implementing and executing JUnit tests for your enterprise level software requirements. OFBiz has an extensive set of out of the box JUnit test cases for the out of the box business processes it supports. At the same time it also provides a rich framework for implementing and executing JUnit Tests for custom OFBiz based software development.

There is a lot that can be written on this topic but in this post we will start with how to setup data for your unit tests and execute them, for both out of the box OFBiz unit tests and custom unit tests.

1) Data Setup and Execution of out of the box JUnit Tests
The out of the box JUnit tests in OFBiz are implemented on top of its demo data. To be more specific the data needed as an input for these unit tests is being modeled and prepared in OFBiz under the data-reader “demo.” To execute these tests using OFBiz demo data you will need to perform the following steps,

  • Execute “run-install” ant target from your console. This will load all the seed, seed-initial and demo data from OFBiz. Once this step is complete, you are now ready to execute the unit tests.
  • Execute “run-tests” ant target from your console. This will run every single unit test from all the out of the box OFBiz components.
  • You could view the test results on the console itself, and test results are also stored in the “runtime/logs/test-results” directory of OFBiz for reference.

2) Data Setup and Execution of custom JUnit Tests
When you are into custom OFBiz based software development you may want to implement JUnit for your customized application. These unit tests have to be programmed in your custom hot-deploy component. The data needed as input to these unit tests has to be modeled under the “ext-test” data-reader of OFBiz. To execute a specific test suite of your custom component you will need to perform the following steps,

  • Execute “run-install-exttest” ant target from your console. This will load all the seed, seed-initial from OFBiz and ext, ext-test data from your custom hot-deploy component needed for your custom test suite. Once this step is complete, you are now ready to execute your custom unit test suite.
  • Execute “run-test-suite” ant target from your console with the following arguments – test.component=”${mycomponent}”; test.suiteName=”${mytests}”. This will run all the unit tests in the specified test suite of your custom hot-deploy component.
  • You can view the test results on the console.

For data setup best practices, as mentioned earlier in this blog, a good practice could be to combine your demonstration data, manual testing data and automated unit testing data and use it cohesively. In out of the box OFBiz, such data should be modeled under the  “demo” data-reader, while for custom OFBiz based development this data is modeled under the “ext-test” data-reader. The database connection settings for testing in OFBiz are configurable. It defaults to the embedded Derby database of OFBiz, but you can change the test delegator configuration in “framework/entity/config/entityengine.xml” file.

To conclude, Apache OFBiz has a very strong support for the automated testing requirements of your enterprise software solution, it is easy to implement and execute them, and it is configurable which is an added advantage.

At HotWax Systems, automated unit testing is an integral part of the software development process and a recommended practice for our developers.

Mridul Pathak About Mridul Pathak
Mridul is an exceptional technologist who began his career as a software engineer with HotWax in 2007. He is currently a senior manager in Enterprise Software Development.With an emphasis on providing training to HotWax Systems employees and clients, he has worked on a variety of projects for clients in North America, Europe and India.Mridul graduated in 2006 from IET DAVV, Indore (M.P) India, with a Bachelor of Engineering(B.E) degree in Computer Science. He loves learning and sharing knowledge. His hobbies are reading novels, writing, collecting and watching movies, and spending time with friends.

Leave a Reply

Your email address will not be published. Required fields are marked *