Test your application's e-mail spam scoring with mail-tester.com

Posted Over 8 years ago by Emanuel.
mail-tester.com

...limited to 3 e-mails per day. Further reading ActionMailer: How to send a test mail directly from the console Debugging SPF records

Fixing flaky E2E tests

Posted Over 6 years ago by Henning Koch.

An end-to-end test (E2E test) is a script that remote-controls a web browser with tools like Selenium WebDriver. This card shows basic techniques for fixing a flaky...

...and seed per process: DISPLAY=:17 bundle exec parallel_cucumber --serialize-stdout --verbose-process-command --test-options '--order random' features/ bin/cucumber --order random --profile parallel features/location/import.feature features/location/export.feature Using the parallel...

Capybara: Testing file downloads

Posted Almost 5 years ago by Emanuel.

Download buttons can be difficult to test, especially with Selenium. Depending on browser, user settings and response headers, one of three things can happen: The browser shows a "Save as...

...through Selenium. The browser automatically downloads the file without prompting the user. For the test it looks like nothing has happened. The browser shows a binary document in its own...

Too many parallel test processes may amplify flaky tests

Posted About 3 years ago by Henning Koch.

By default parallel_tests will spawn as many test processes as you have CPUs. If you have issues with flaky tests, reducing the number of parallel processes may help.

...Flaky test suites can and should be fixed. This card is only relevant if you need to run a flaky test suite that you cannot fix for some reason. If...

Lightning Talk: Coverage based Test Case Prioritization in Ruby on Rails

Posted 8 months ago by Felix Eschey.
github.com

For my computer science bachelor's thesis I programmed and evaluated a CLI Test Case Prioritization (TCP) tool for makandra. It has been written as a Ruby Gem and was...

...modifications, to prioritize test cases which might be failing due to these modifications. Newly added test-cases have to granted high priority within the calculated prioritization. Test Case Prioritization

Test-Driven Development with integration and unit tests: a pragmatic approach

Posted About 4 years ago by Dominik Schöler.

Test-Driven Development (TDD) in its most dogmatic form (red-green-refactor in micro-iterations) can be tedious. It does not have to be this way! This guide shows a...

...who originally coined the term "TDD" in the late 90s) summarizes the key aspects of test-driven development...

Testing ActiveRecord validations with RSpec

Posted About 8 years ago by Henning Koch.

Validations should be covered by a model's spec. This card shows how to test an individual validation. This is preferrable to save an entire record and see whether it...

Recipe for testing any validation In general any validation test for an attribute :attribute_being_tested looks like this: Make a model instance (named record below) Run validations...

Capybara: Finding invisible elements and how to test that an element is not visible

Posted Over 2 years ago by Arne Hartherz.
github.com

...you are using a driver that supports it (e.g. Selenium, not the default Rack::Test driver). Consider the following HTML: One Two With some CSS: .test1 { display: block } .test2 { display...

...or visible: true As described above, by default Capybara finds only visible elements. find('.test1') finds the .test1 element find('.test2') raises a Capybara::ElementNotFound error, as the .test2 element...

Ensure passing Jasmine specs from your Ruby E2E tests

Posted Over 2 years ago by Henning Koch.

Jasmine is a great way to unit test your JavaScript components without writing an expensive end-to-end test for every small requirement. After we integrated Jasmine into a Rails...

...app we often add an E2E test that opens that Jasmine runner and expects all specs to pass. This way we see Jasmine failures in our regular test runs.

Rails: Testing file downloads with request specs

Posted 2 months ago by Julian.

Prefer request specs over end-to-end tests (Capybara) to joyfully test file downloads! Why? Testing file downloads via Capybara is not easy and results in slow and...

...fragile tests. We tried different approaches and the best one is just okay. Tests for file downloads via Capybara ... ... are slow, ... are fragile (breaks CI, breaks if Selenium driver changes...

Using feature flags to stabilize flaky E2E tests

Posted Over 2 years ago by Henning Koch.

A flaky test is a test that is often green, but sometimes red. It may only fail on some PCs, or only when the entire test suite is run.

...are many causes for flaky tests. This card focuses on a specific class of feature with heavy side effects, mostly on on the UI. Features like the following can amplify...

Testing shared traits or modules without repeating yourself

Posted Over 10 years ago by Henning Koch.

...should extract that behavior into a trait or module. This card describes how to test that extracted behavior without repeating yourself. Note that the examples below use Modularity traits to...

...app/models/page.rb class Page < ApplicationRecord include DoesSanitizeHtml end # app/models/template.rb class Template < ApplicationRecord include DoesSanitizeHtml end Testing test trait usage with a shared example group When two classes share behavior through a...

Best practices: Writing a Rails script (and how to test it)

Posted 4 months ago by Dominik Schöler.

...so you can build on previous scripts for a similar task You can have tests (see below) Although not part of the application, your script is code and should adhere...

...ActiveRecord::RecordInvalid # Handle error end On error, log the record for manual care. Consider testing your script Not every script needs a test. However, sometimes you'll want to add...

Split your parallel tests by execution time and keep execution logs up to date

Posted 8 months ago by Felix Eschey.

Both knapsack and parallel_tests have the option to split groups by historic execution time. The required logs for this might be outdated since you manually have to update and...

...no extra effort locally and/or remotely. How to always split by execution logs Parallel Tests The parallel_tests gem has the option flag --group-by to change the default splitting...

Faking and testing the network with WebMock

Posted Over 13 years ago by Henning Koch.
github.com

...saving you the effort to stub out request/response cycles in close details. If your tests do require close inspection of requests and responses, Webmock is still the way.

...an alternative to FakeWeb when testing code that uses the network. You should probably learn it together with RestClient, which is an awesome alternative to net/http and shares many concepts...

Capybara: Most okayest helper to download and inspect files

Posted About 2 years ago by Henning Koch.

Testing file download links in an end-to-end test can be painful, especially with Selenium. The attached download_helpers.rb provides a download_link method for your Capybara tests. It returns...

...other approaches this helper has many useful features: Works with both Selenium and Rack::Test drivers without limitations. Understands the [download] and [download=filename.ext] attributes. Allows filename, disposition, content type...

RSpec: Debug flickering test suites with rspec --bisect

Posted About 7 years ago by Tobias Kraze.
rspec.info

In modern default RSpec configurations, your tests are usually run in random order. This helps to detect "flickering" tests that only fail when run in a certain order.

...for this are tests that have side effects causing other tests to fail later. The hard part is to find the offending test. Enter rspec --bisect: Say you have a...

Jasmine: Cleaning up the DOM after each test

Posted Over 1 year ago by Henning Koch.

...DOM elements often leave elements in the DOM after they're done. This will leak test-local DOM state to subsequent tests. For example, this test creates a element, runs...

...butler did it') }) }) To address this I like to configure a global container for test elements, which is cleared automatically after each test. By including the following helper hooks your...

Cucumber: Identifying slow steps that drag down your test speed

Posted Over 6 years ago by Dominik Schöler.
relishapp.com

In most projects I know, Cucumber test suite speed is not an issue. Of course, running 350 features takes its time, but still each test for itself is reasonably fast...

...There is nothing you can do to fundamentally speed up such a test (of course, you should be using parallel_tests). However, in projects that go beyond clicking around in...

Timecop: reset after each test

Posted Over 1 year ago by Daniel Straßner.

Timecop is a great gem to set the current time in tests. However, it is easy to introduce flakyness to your test suite when you forget to reset the time...

...after the test. This might be the case if: a test freezes time and a later test does not work for frozen time a later test needs the real current...

The Self-Contained Test

Posted Almost 4 years ago by Henning Koch.
thoughtbot.com

...Yourself (or DRY if you prefer). Identical blocks of code to set up a test sure does look like repetition, so we extract it into a before block.

...a mistake for tests. The article explains about how sharing setup between examples make test files harder to read and evolve. A related frustration I have is working on ultra...

Raising JavaScript errors in Ruby E2E tests (RSpec, Cucumber)

Posted Over 5 years ago by Henning Koch.

A JavaScript error in an E2E test with Selenium will not cause your test to fail. This may cause you to miss errors in your frontend code. Using the BrowserConsole...

...helper below you can check your browser's error console from your E2E tests. The following will raise BrowserConsole::ErrorsPresent if there is an error on the browser console: BrowserConsole.assert...

open-next-failure: An alias to speed up test debugging

Posted 5 months ago by Michael Leimstädtner.

Getting an entire test suite green can be a tedious task which involves frequent switches between the CLI that is running tests back to the IDE where its cause can...

...example_status_persistence_file_path as it allows RSpec to keep track of failing tests. See this card for set-up instructions. If you don't use RSpec for all...

How to: Rails cache for individual rspec tests

Posted Almost 7 years ago by Emanuel.

...environments except production: config.action_controller.perform_caching = false config.cache_store = :null_store If you want to test caching you have at least two possibilities: Enable caching for every test (not covered by...

...this card and straightforward) Enable caching for individual test Enable caching for individual test (file cache) 1. Leave the default configuration 2. Add a caching helper which gives you a...