spring-test

Incite database failure for integration test

When running an integration test (Web Service talking to JDBC, in this case) how do you force the database to throw an error so that the resulting soap fault can be inspected? I'm using Spring's Transactional Test Framework, so would be unreasonable to just issue a DROP TABLE whatever; to break it? :D ...

Putting Spring integration tests in different classes and packages

I am using AbstractTransactionalSpringContextTests to run spring integrations tests. The spring context is loaded just once and then all the tests are run. How do I do the same if I want my tests to be in many classes and packages. Of course, the spring context should be loaded just once for all my tests (in all classes and packages), a...

Spring context tests can't find config locations

I have a large application spread across multiple Spring bean definition xml files. In my test suite I manually load up the XML files I need using a FileSystemXmlApplicationContext to perform the tests I want to run. This reduces test set up time and allows me to use the same exact configuration files that are used in production. Now I...

DBUnit: How to refresh only on failure ?

I am using DBUnit to test a Spring/Hibernate persistence. I created an abstract test: public abstract class AbstractTestCase extends AbstractTransactionalDataSourceSpringContextTests { @Override protected String[] getConfigLocations() { return new String[] { "classpath:/applicationContext.xml", "classpath:/testDataSource...

How to mock a static variable in java using JMock

Hello, I have a Unit testing problem where a class has a static variable which wants to load the Spring Application Ctx. This class DOES NOT come out of the Bean Factory and I cannot change this fact. static ApplicationContext applicationContext = ...; This works fine, but is hard to JMock, or atleast I don't know a way and until I...

SpringJUnit4ClassRunner initialize beans for each test?

The following test illustrates that this test bean is initialized twice by Spring. I'm hoping someone can tell me why this is so, since it should only be once. Here's the test: import org.apache.log4j.Logger; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.InitializingBean; import org.s...

Spring Tests : transaction not rolling back after test method executed

Hi ! I'm trying to create integration tests for a legacy application deployed on Weblogic 8.1 using a subclass of AbstractTransactionalJUnit4SpringContextTests. My test method has the following annotations : @Test @Rollback(true) public void testDeployedEJBCall throws Exception {...} My test class also references beans of type org.s...

request scoped beans in spring testing

I would like to make use of request scoped beans in my app. I use JUnit4 for testing. If I try to create one in a test like this: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:spring/TestScopedBeans-context.xml" }) public class TestScopedBeans { protected final static Logger logger = Logger...

Is automatic rollback of DAO integration tests with Spring Test a good practice?

If I were to annotate my DAO integration test methods with @Transactional, Spring Test will happily rollback any changes to the database after each test methods completes. These seems extremely convenient, because I can load the test data once with a @BeforeClass method and all clean up is handled for me. But I question whether this is...

How to load DBUnit test data once per case with Spring Test

Spring Test helpfully rolls back any changes made to the database within a test method. This means that it is not necessary to take the time to delete/reload the test data before each test method. But if you use the @BeforeClass Junit annotation, then that forces the data loader to be static. A question that is explored here: http:...

Spring Test Framework and annotation-based autowiring Problem

Hi I would like to use two different implementations for a DAO with Spring's testframework. src.main.java .businessobjects \-User.java .dao \-IUserDAO.java .daojpa \-UserDAO.java .daohibernate \-UserDAO.java The spring testcase in: src.test.java.base: package base; import org.junit.runner.RunWith; import org.springfr...

JUnit tests pass in Eclipse but fail in Maven Surefire

I have written some JUnit tests using JUnit 4 and spring-test libraries. When I run the tests inside Eclipse then run fine and pass. But when I run them using Maven (during the build process), they fail giving a spring related error. I am not sure what is causing the problem, JUnit, Surefire or Spring. Here is my test code, spring config...

How can I write portlet tests using spring-test package?

I'm trying to test my portlet controllers written using Spring but I don't know how to use org.springframework.mock.web.portlet package. There are lot of examples for org.springframework.mock.web but lack of examples for mocking portlets using Spring. Can anyone show me an example test for portlet controllers? ...

How can I make Spring testcontext framework use multiple data sources?

I'm trying to integration test my application with Spring TestContext framework. I have done this by extending AbstractTransactionalJUnit4SpringContextTests, as usual. However, my application has three different data sources (with names like xDataSource, yDataSource, zdataSource), så when I try to run the test, the autowiring of data sou...