私は自分のクラスのテストを作成しているので、コードをテストするために非常に多くのデータを挿入しています。
そこでsavepoint and rollback
、DBに何らかの仕組みを作ろうと考えています。
DBサーバーとして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()
ここでは、コマンド オブジェクトを介して値を設定し、休止状態を使用して DB 内にデータを格納するメソッドに渡します。それでも、データが正しいかどうかをチェックするメソッドを書くassert
必要testProcess()
がありますか?
したがって、私の質問は、このトランザクションがsetUp()
メソッドで開始されたときに、1 つのセーブポイントを作成してからtestProcess()
メソッドを実行assert
し、データが正しいかどうかを確認してから、メソッドtearDown()
で設定されているセーブポイントにロールバックしたいということですsetUp()
。
では、どうすればよいのでしょうか。誰かが私が何を使用し、どのように前進するかを教えてくれるなら、私はそのことを学び、自分で行きます.
何をどこで使用する必要があるかについてのガイダンスが必要です。皆さん、ありがとうございました。