(no title)
pskinner | 4 years ago
This approach is terrible and causes the poor performance.
There are whole sets of testing "tools" for RoR projects that promote this mechanism of testing - if you're testing an API you need to use an external tool to properly hit that API.
If you're writing unit tests, write unit tests with mocked dependencies.
ch4s3|4 years ago
Lots of RoR projects do unit testing without the DB involved, I did it for ~10years and you can write small unit tests until your eyes bleed, but eventually you'll want to test the controllers.
> There are whole sets of testing "tools" for RoR projects that promote this mechanism of testing - if you're testing an API you need to use an external tool to properly hit that API.
You can just use the built in minitest tools and some fixtures to hit the API, and even back it with sqlite so it's fast and light. Most people don't because thing like Rspec, FaktoryBot, and Cuprite are convenient and nice to work with if a bit slow.
>If you're writing unit tests, write unit tests with mocked dependencies.
There were like 3 talks at Rails Conf about this, people do it all the time in Rails land.
pmontra|4 years ago
The teams I work with tend to write unit tests to demonstrate that a class or module or whatever work, then integration tests to demonstrate that that part of the application works from the frontend code down to the database.
quesera|4 years ago
This is not correct.
Rails projects use unit testing, integration testing, and functional testing, as appropriate for the case.
realusername|4 years ago
Especially that we're talking about a web framework, the db is a core part of your stack.
Yes there's going to be strictly unit tests but then at some point there are also queries and models.
syspec|4 years ago
I'll take hitting real "_test" db anyday
touisteur|4 years ago