Hello DEV.to community!
I am a bit nervous to ask this question here. But I really need your help on this.
I am new to ruby and test driven development. I just wanted to know how you guys do Integration testing in your rails project. Integration test are too slow and sometime fails. I want to know how you guys do Integration testing in your projects and make them faster. Also how you manage to do testing for different screen sizes like mobile and tablets.
I am a beginner rubyist. If you can suggest any good platform/community to ask this ques please recommend that too. 😁
Top comments (2)
People will often reach for Capybara to do integration testing.
Like you mentioned, integration tests can be slow. One thing that's helped me over the years is to make sure you're using the correct driver. For example, if you don't need the JavaScript driver, try not to use it. If you're using Capybara + Rspec, the JavaScript driver is enabled by the
js: true
flag. In my experience, these tests will always run slower because it spins up a full browser instance. If you're using the JavaScript driver needlessly, you'll bloat your test suite when you don't really need to.In other projects, I've had good luck using chromedriver (github.com/flavorjones/chromedrive...). You can run it in headless mode. It feels much faster than webdriver + Firefox. I have a small web app covered almost 100% by integration tests and I don't feel like it's too slow.
Test driven development is a huge subject. Just remember integration testing is just part of it. It's helpful to use integration tests, but it doesn't have to be your whole test suite. You can also do separate runs of unit tests and integration tests. If your unit tests fail, you know something is wrong and you don't have to run the integration tests.
I have used Capybara alot and hesitate to recommend it. You're frontend runs and works with JS (probably) not Ruby. So acting like JS doesn't exist can lead to faulty integration testing, which is super frustrating.
Pros:
Fairly fast
Can use a multitude or browser drivers
Integrated in Rails
Cons:
JS sucks when using Ruby driven integration tests
I would recommend looking at Nightwatch.js if you're building a test suite from nothing.
Pros:
Fairly fast
Can use a multitude or browser drivers
JS integration rocks!
Cons:
Not integrated into Rails
I like to think of integration testing as acceptance tests or happy path testing. You don't want to test business logic with integration testing, you want to ensure that your UI responds in ways that you expect. Its a smoke test to ensure that your UI is responding appropriately.