1

We are currently attempting to implement the Togglz library in Spring-MVC.

We currently manage the toggles in our code from our MyFeatures.java file in the following way:

import org.togglz.core.Feature;
import org.togglz.core.annotation.EnabledByDefault;
import org.togglz.core.annotation.Label;
import org.togglz.core.context.FeatureContext;

public enum MyFeatures implements Feature {

    @Label("A Feature")
    MY_FEATURE;

    public boolean isActive() {
    return FeatureContext.getFeatureManager().isActive(this);
    }
}

and then in our actual classes with:

if (MyFeatures.MY_FEATURE.isActive()) {
    // some code...
}

This works well but we have a deficiency in our tests where we do the following:

@Rule
public TogglzRule togglzRule = TogglzRule.allDisabled(MyFeatures.class);

// some tests, then:

    if (MyFeatures.MY_FEATURE.isActive()) {
        // some feature dependent test...
    }

The issue here is that our toggles in MyFeature.java are defaulted to disabled, and toggled on/off from either our UI or within this MyFeatures.java file. BUT... our toggles in the tests are defaulted to enabled and toggled on/off with either the line:

@Rule
    public TogglzRule togglzRule = TogglzRule.allDisabled(MyFeatures.class);

or individually in each test.

This is AT LEAST two places we have to toggle off our features, maybe more if we have more tests using those features, so my question is:

Is it possible to control all the Togglz feature toggles from a single place, regardless of whether they are in the code or the tests?

Joe
  • 678
  • 9
  • 24

1 Answers1

1

The issue here is that our toggles in MyFeature.java are defaulted to disabled, and toggled on/off from either our UI or within this MyFeatures.java file.

Changing the features state in this file or from UI affect the application behavior in production environment (and thus possible users).

BUT... our toggles in the tests are defaulted to enabled and toggled on/off with either the line:

Changing the features state in the tests affect the application behavior under the tests.

This is AT LEAST two places we have to toggle off our features, maybe more if we have more tests using those features

What you are asking is controversial because if such possible would exist, it will affect both environments (testing and production). This fact will lead to the following:

  • when you're disabling some feature, tests starting to fail, because they're relying on this feature and tries to test it
  • then you're enabling this feature, tests are passing but now there is a chance that users could see a feature that isn't ready yet

So this separation exist for the purpose and managing the features state from 2 different places is actually a feature and not a bug.

Another idea that I've heard that in most cases you shouldn't test the cases when feature is disabled because such state should be temporary and doesn't worth an effort of maintaining tests of all possible cases.

Slava Semushin
  • 14,904
  • 7
  • 53
  • 69