top | item 29984040

(no title)

pskinner | 4 years ago

This is because RoR projects do not do unit testing, they do integration testing with a real DB.

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.

discuss

order

ch4s3|4 years ago

> This is because RoR projects do not do unit testing, they do integration testing with a real DB.

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

It's hard to really test business logic without hitting the database or other components, no matter the language and the framework. You really have to trust your mocks and sometimes you discover only in production that one of them didn't do what it should do. It happened to me.

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 because RoR projects do not do unit testing, they do integration testing with a real DB.

This is not correct.

Rails projects use unit testing, integration testing, and functional testing, as appropriate for the case.

realusername|4 years ago

If you write all yours tests without spinning up once a database, I'm not vouching for the effectiveness of said tests...

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

Oh the number of times I've run my tests for springboot in which passed, only to fail because of a subtle db issue when hitting the real DB

I'll take hitting real "_test" db anyday

touisteur|4 years ago

Might be a place to bypass fsync/fdatasync via LD_PRELOAD using libeatmydata, it will save hours of CI time without switching DAO or DB configuration.