Should rail tests test the database or not?

I wrote tests for my rails application. I use TestUnit for installation as well as functional tests. And I also use cucumber to test the GUI.

But I find that http://www.dcmanges.com/blog/rails-unit-record-test-without-the-database says that it is better that unit tests not get into the database.

I agree that a successful database takes a lot of time. I already use spork to reduce the burden on the environment.

What is the best practice when testing a rails application?

+3
source share
4 answers

, . Rails , ActiveRecord "" , , , . , , , , , ; , , .. .

, ActiveRecord . Rails , ; . , , ActiveRecord ( ). , , , , .

. ActiveRecord ActionController , , . , Rails - . , , , . , , ActiveRecord "" , - "" ( , , , rspec).

, , ( ). , , , . , / , , . , , .

+18

. . , , , ( , ). / , unit test.

( Cucumber, ) MVC ,

+4

, "Rails way" " , ", - , ", , , ?".

Rails, , , " Rails-", , 100 . , "" ( , , , ).

: , . , , , , .

, , , , - .

" ", HTTP-. " ". , , , , (, , ).

+1

Use a fast in-memory database for unit testing. If you want to test “methods as expected, if the data you need is available”, it’s best to use a dataset that closely resembles your actual dataset. The in-memory database may contain very small or rather large data sets depending on your needs. HSQLDB is supported by ruby ​​rails and is commonly used for unit testing.

0
source

Source: https://habr.com/ru/post/1776896/


All Articles