简体   繁体   中英

Test or not test?

Today i begin a project that i must to spread a backend in two pieces, i dont know what exactly does the backend do, only that i have to move specific services into new spring, jersey, maven multi module project.

So, the task to move was really easy and now its time to write tests. Previously, the project does not have any test.

When i start to write a JUnits from my Business Objects, i saw, that most services only perform a basic operation with a DAO, like getAll, get, save, update and delete. The other services got bussines validation, but it is not comlpex.

So the questions are more theorical:

Should i write JUnits to test a simple DAO get that will be mocked (no integration test) which will be the benefits for do this? Which will be the correct way to make a integration test for a simple DAO get, getAll, or create (create that does not have any validation to execute before)

Unit&Integration tests are for developers, so if you don't feel like some developer will benefit from the test - don't write it. Also consider that tests verify behavior, not code, so if you don't see any behavior that needs testing - don't spend the time.

In your case I would at most write integration tests for services, and maybe for DAOs (if there is no ORM).

Anyway correct answer to your question depends on the level of quality that you need to provide for your project, team size, potential of destructive code changes, etc.

Two examples:

1) Small site's admin-panel in CRUD style, only one developer introduces changes simultaneously, and almost no business logic is present. Bugs presence is non-critical.

In this case I would not spend the time on any tests - most likely you need to focus on other things (eg client-side).

2) You are starting a complex project, that is currently in CRUD style, but interactions between distant services/DAOs are present, business logic tends to become complex at some time. Team is rapidly growing/changing, more than one person involved, new developers can't understand how the system works easily. Bugs presence are bad for business.

In this case I would at least start with integration tests for services.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM