Let's take a look at that next.ĭerby is a very interesting project with a history with some twists and turns. So the next configuration step I need to make is to get Maven to automatically start and stop a database and fill it with data for my integration tests to use. For these example integration tests, a database is needed. Remember, integration tests partially rely on external resources. Now that I have my *IT.java files and I have the maven-failsafe-plugin configured in the pom.xml, the integration tests are ready to run right? Well not quite yet. This integration test will attempt to insert data into a database then query to find it. The second is SomeTableInsertAndFindIT.java. This integration test will attempt to find existing data in the database. The first is SomeTableFindExistingIT.java. In this article's project ( download), I have two integration test examples. Listing 1 : Add maven- failsafe-plugin to project's build. Listing 1 shows you how to add the plugin to your project's. To get integration tests to run the maven-failsafe-plugin must be configured in your project's pom.xml. However the difference is that integration tests use real external resources more and rely on mock objects less.Īfter creating *IT.java integration tests you may run your Maven default life cycle and expect the integration tests to run. In fact the test itself is written almost exactly as if it were a unit test. You annotate the *IT.java with the same annotations you would use for a unit test. The most popular pattern is *IT.java since it most closely matches its unit test counterpart *Test.java. For integration tests, the default file matching name patterns are as follows:Īs you can see, these file name patterns are different than they are for unit tests. Integration testing is performed by the maven-failsafe -plugin during the integration-test phase of the life cycle. Now we'll talk a bit about integration-testing. It's nice that unit-testing works so easily, and you'd think it would be the same for integration-testing, but it's not. Simply create a src/test/main/ * */*Test.java class and Maven will automatically execute it for you. There is no configuration needed to run simple unit tests. Unit testing is performed by the maven-surefire-plugin during the test phase of the life cycle. We'll first talk a bit about unit-testing because it is probably something you are already familiar with and we'll use this familiarity to springboard into integration-testing. Let's learn a little more about each one. Unit-testing you get for free, but integration-testing is a bit more complicated. Both are driven off the Maven execution life cycle. The Maven world has two kinds of testing: unit-testing and integration-testing. So executing mvn test won't run the integration test examples! The unit testing phase of the Maven lifecycle. The project contains Maven integration tests which are NOT run during Or, within NetBeans, right-click on the project and select "Clean and Build". Simply execute mvn from the command line after changing to the MavenIntegrationTestingWithDerby directory. If you just want to look at the project demonstrating the solution, download the code example from GitHub ( ). The rest of the software dependencies can be found in the project's pom.xml. If yours is different, it may work but no guarantees. The code was developed and run using the following system setup. not relying on an external database server? The purpose of this article is to explore quick and easy integration testing with Maven and an in-memory Derby database. But how? And more importantly, how to do it quickly and easily - i.e. Now you are ready to move to the next step - integration testing and verifying the SQL itself. Following strict unit testing guidelines you have mocked your data access up to this point (to avoid access to an external resource) and have verified your business rules. Your project contains a lot of SQL and you want to test it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |