Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When/How to Unit Test CRUD applications?

I've been hearing alot about unit testing lately.

What I'm trying to understand is how would one / should one go about unit testing a cruddy business app? (basically an app that writes data in / reads data out of a database).

Is unit testing even worth it in that scenerio or do you usually unit test more complicated things?

Thanks

like image 756
Shai UI Avatar asked Jul 09 '10 17:07

Shai UI


People also ask

When should the unit testing be performed?

Unit testing is the first testing phase and it is practiced before moving to the phase of integration testing. Hence, before moving for the next testing level, make sure to fix all the identified bugs in the unit testing phase.

How do you test for CRUD operations?

Definition of CRUD Create – INSERT an entry in the Database. Read or Retrieve – SELECT the entry from the Database and View it. Update – UPDATE the entry completely or partially. Delete or Destroy – DROP/DELETE the entry.

Is unit testing done after deployment?

No. Deployments don't include tests nor the supporting libraries (e.g. unit test libraries, mocking etc.)


2 Answers

Unit testing is about testing discrete units of code - a single method, no more.

The moment you go into CRUD, you are talking about testing network, IO, database and other things - this is beyond what unit testing is about. In this case, this is called integration testing (you are testing how your code integrates with other code/systems).

There is place for both types of testing (and other types - regression, performance etc...) in any software project, CRUD application or not.

like image 92
Oded Avatar answered Sep 25 '22 20:09

Oded


If all your application does is CRUD, then there is no point in unit testing it. Now, if there is any kind of business logic manipulating the values as they come out of the db or validating them before them going in, yes, it is a good idea to build unit tests. Testing the CRUD part does not belong in unit testing IMO.

like image 29
Otávio Décio Avatar answered Sep 23 '22 20:09

Otávio Décio