Info |
---|
Help is available by sending an email to csf-support@mit.edu |
Panel | ||||
---|---|---|---|---|
Quick Links to:
|
Panel |
---|
DefinitionIn our applications and framework, we have used the term "integration test" to describe a written JUnit test case that requires a full Spring context (including all the framework classes), and actually talks to the MITSIS Oracle database. An integration test is disctinct from a pure unit test, which typically uses mock objects for dependencies, and does not talk to the database. We mainly use integration tests for testing DAO classes, but they could possibly be used also for testing service classes and MVC controllers. |
Panel |
---|
HistoryUp until now (July 2012) our integration test cases (mainly used for testing DAO classes) have extended a base class BaseTransactionalIntegrationTest, which in turn extends deprecated Spring classes. This base class provided unit tests with a default Spring context and an automatic rollback capability. Unit tests extending this base class were automatically database-aware, and any updates done in the unit test were automatically rolled back at the end of the test. Spring has deprecated the class that BaseTransactionalIntegrationTest extends, and now recommends a different way of coding integration unit tests (see Spring Javadoc). The following section describes changes we are making to move away from the deprecated classes. |
Panel |
---|
The CSF AbstractIntegrationTestBase.java unit test base classCSF now has a new abstract class, AbstractIntegrationTestBase class, found in the csf-test module. This class uses JUnit and Spring annotations to gain access to functionality previously provided by extending the deprecated Spring class AbstractTransactionalDataSourceSpringContextTests. This CSF abstract class is to be used with all integration tests. It replaces the following deprecated classes
that were used in csf-common-legacy. |
Panel | ||||||
---|---|---|---|---|---|---|
About the AbstractIntegrationTestBase base classBelow is a complete listing of the AbstractIntergrationTestBase class. Of particular interest is the usage of the @Transactional and the @ContextConfiguration annotations.
The locations element of the @ContextConfiguration only specifies one xml file. This xml file is used to set the default test application context for ALL unit tests which extends AbstractIntegrationTestBase.java class. At the bottom of this page is more information on how to configure and how to override the default test application context.
|
Panel | ||||
---|---|---|---|---|
Usage of the AbstractIntegrationTestBase base class
|
Panel | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
How to configuration the default test application contextThe annotation
is used to set the default test application context for all the junit tests which extend the AbstractIntegrationTestBase .java class. If the project was created using the es-project-template (for either the jar or war) then the applicationContext-csf-unit-tests-default.xml file can be found it the project's src/test/resources directory. If the project was NOT created using the es-project-template, then the applicationContext-csf-unit-tests-default.xml must be created in the project's src/test/resources directory. To download the a starter version of the applicationContext-csf-unit-tests-default.xml file, right click on this link and select Save target as.... Be sure to save the file in the project's src/test/resources directory. The following is a listing of the starter version of the applicationContext-csf-unit-tests-default.xml file:
The following is an example from the Student Sponsored Billing application and is an example on how to customize the applicationContext-csf-unit-tests-default.xml file.
The order in which the xml files appear is important. Just remember the beans are instantiated in the order that they are processed and, if needed, overriding previous bean instantiations with identical ids. |
Panel | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
How to override for the default test application contextThe following code fragment illustrates how to override the default test application conxtext:
This applicationContext-special-authorization-test.xml must also exist in the project's src/test/resources directory. This xml file will contain a list of imports of application context xml files. For example, the contents of this xml file might look like:
|