开发者

Oracle DB testing strategy

At work we are trying to simplify an application that was coded with an overkill use of Spring Remoting. This is how it works today:

(Controllers) Spring MVC -> Spring Remoting -> Hibernate

Everything is deployed in a single machine, Spring Remoting is not needed (never will be needed) and adds complexity to code maintenance. We want it out.

How to ensure everything works after our changes? Today we have 0% code coverage! We thought on creating integration tests to our controllers so when we remove Spring Remoting they should behave exactly the same. We thought on using a mix of Spring Test framework in con开发者_StackOverflow社区junction with DBUnit to bring up Oracle up to a known state every test cycle.

Has anyone tried a similar solution? What are the drawbacks? Would you suggest any better alternative?


It always depends on the ratio effort / benefit that you are willing to take. You can get an almost 100% code coverage if you are really diligent and thorough. But that might be overkill too, especially when it comes to maintaining those tests. But your idea is good. I've done this a couple of times before with medium applications. This is what you should do:

  1. Be sure that you have a well known test data set in the database at the beginning of every test in the test suite (you mentioned that yourself)
  2. Since you're using Hibernate, you might also try using HSQLDB as a substitute for Oracle. That way, your tests will run a lot faster.
  3. Create lots of independent little test cases covering most of your most valued functionality. You can always allow yourself to have some minor bugs in some remote and unimportant corners of the application.
  4. Make sure those test cases all run before the refactoring.
  5. Make sure you have a reference system that will not be touched by the refactoring, in order to be able to add new test cases, in case you think of something only later
  6. Start refactoring, and while refactoring run all relevant tests that could be broken by the current refactoring step. Run the complete test suite once a night using tools such as jenkins.

That should work. If your application is a web application, then I can only recommend selenium. It has a nice jenkins integration and you can create hundreds of test cases by just clicking through your application in the browser (those clicks are recorded and a Java/Groovy/other language test script is generated).


In our Spring MVC / Hibernate (using v3.4) web app we use an Oracle database for integration testing.

To ensure that our database is in a known state each time the test suites are run, we set the following property in our test suite's persistence.xml:

<property name="hibernate.hbm2ddl.auto" value="create"/>

This ensures that the db schema is created each time our tests are run based on the Hibernate annotations in our classes. To populate our database with a know data set, we added a file named import.sql to our classpath with the appropriate SQL inserts. If you have the above property set, Hibernate will run the statements in import.sql on your database after creating the schema.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜