# Testing

> Advice and insights related to best practices for testing feature flags in your application.

Since 1.2.0, Flipper will default to the `Memory` adapter when running tests in a Rails app and reset it before each test. This means each test is run with a fresh instance of Flipper and all features disabled. We find this the best route, but your application **may** have different needs. If you want some features to always be enabled, you can enable them in your test setup.

```ruby
class ActiveSupport::TestCase
  setup do
    Flipper.enable :accounts
    Flipper.enable :fathom
  end
end
```

In the example above, the `accounts` and `fathom` features would both start enabled for every test. Every other feature flag would start disabled.

## Test Both Sides

For any feature flag, we strongly encourage you to have at least one test for when the feature is enabled and disabled. This ensures both sides of the coin are tested.

```ruby
require 'test_helper'

class DocumentationControllerTest < ActionDispatch::IntegrationTest
  test "returns 404 for documentation when feature disabled" do
    Flipper.disable(:docs)
    get documentation_path
    assert_response :not_found
  end

  test "renders documentation when feature enabled" do
    Flipper.enable(:docs)
    get documentation_path
    assert_response :success
  end
end
```

## System Tests

The default configuration for testing should work for [system tests](https://guides.rubyonrails.org/testing.html#system-testing) just as any other test. [Let us know on this issue](https://github.com/flippercloud/flipper/issues/615) if you run into any issues.

## Advanced

For non-Rails apps or Flipper <1.2, see [test_help.rb](https://github.com/flippercloud/flipper/blob/main/lib/flipper/test_help.rb).
