Reputation: 1537
My application has a custom server component.
We have some JUnit test cases for the business logic with JMockit in place to mock the DB layer.
For integration testing, we end up having a lot of similar conditions to check. The only difference is that I need to serialize stuff and send to a socket instead of just making a call.
Is there any (simple) way to generalize the tests so that I can specify those conditions once for both tests?
Upvotes: 2
Views: 1954
Reputation: 4177
Your unit and integration tests are just another piece of code which would need to be applied the statndard concepts you have for your main stream code. So, things like writing reusable code, using design patterns, coding to interfaces and finally continuous refactoring would hold true for tests as well.
Following SO threads have more advice:
Hope that helps.
Upvotes: 0
Reputation: 14755
> Is there any (simple) way to generalize the tests so that I can
> specify those conditions once for both tests?
You can put the tests into a baseclass with a virtual FactoryMethod that constructs helper-objects.
Your unittest und integrationtest inherits from that class. The implementation of the FactoryMethod creates either some mock or some real object.
Upvotes: 1
Reputation: 11076
You could add the rules to a file which you can reference from the integration test and the unit tests.
You should write it in some kind of domain specific language which can be read by non-technical stakeholders but can also be parsed, e.g.:
discount: 10% for: orders over $10
discount: 20% for: orders over $40
discount: 30% for: orders over $100
Upvotes: 0