我正在测试我的课程,所以我插入了这么多数据来测试我的代码。
所以我想savepoint and rollback
在数据库中建立一些机制。
我使用 postgresql 作为数据库服务器。
以下是我的测试代码:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration("file:src/main/webapp/WEB-INF/ls-dispatcher-servlet.xml")
public class AddBindingProcessorTest extends IntegrationTestBase {
@Autowired
private AddBindingProcessor processor;
public AddBindingProcessorTest(){
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void add() throws Exception {
AddBinding command;
command = new AddBinding();
command.setId(50l);
command.setBindingName("bindingtest1");
command.setBindingPrice((double)253);
BindingTypeResponse response = (BindingTypeResponse)processRequest(command);
System.out.println("from addbindingprocessor test "+response.getBindingName());
}
}
在这里,我通过命令对象设置值并传递给ProcessRequest()
将使用休眠将数据存储在数据库中的方法。我仍然必须assert
在我的testProcess()
方法中编写检查数据是否正确?
所以我的问题是,当这个事务在setUp()
方法中开始时,应该创建一个保存点,然后testProcess()
执行方法并assert
检查它们是否正确的数据,然后在tearDown()
方法中我想回滚到setUp()
方法中设置的保存点。
那么该怎么做呢?如果任何人都可以指导我将使用什么以及如何前进,那么我将学习那件事并自己去。
我只是想要关于我必须使用什么以及在哪里使用的指导?谢谢你们。