Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When unit testing, do you have to use a database to test CRUD operations?

When unit testing, is it a must to use a database when testing CRUD operations? Can sql lite help with this? Do you have to cre-create the db somehow in memory?

I am using mbunit.

like image 916
mrblah Avatar asked Sep 27 '09 21:09

mrblah


People also ask

Should unit tests require a database?

Unit tests shouldn't depend on infrastructureThere's no way to test this function without having a database connection available at the time of testing. If a new developer clones the project they will need to set up a database or else tests will fail.

Should you unit test CRUD?

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.

Do databases do unit testing?

SQL unit testing is a testing method which allows us to test the smallest, atomic programmable part of a database object. SQL unit testing plays a key role in the modern database development cycle because it allows us to test individual parts of the database objects work as expected.


1 Answers

No. Integrating an actual DB would be integration testing. Not unit testing.

Yes you could use any in-memory DB like SQLite or MS SQL Compact for this if you can't abstract (mock) your DAL/DAO in any other way.

With this in mind I have to point out, that unit testing is possible all the way to DAL, but not DAL itself. DAL will have to be tested with some sort of an actual DB in integration testing.

like image 103
Robert Koritnik Avatar answered Oct 06 '22 19:10

Robert Koritnik