Skip to content

Class-level @IfProfileValue overrides method-level @IfProfileValue settings [SPR-5902] #10571

Closed
@spring-projects-issues

Description

@spring-projects-issues

Konstantin Boudnik opened SPR-5902 and commented

It seems that current implementation of @IfProfileValue is deficient for the following reasons:

  • it is possible to create a mutual-lock situation when none of a class' test methods would be executed no matter what values are set in the runtime
  • current semantic contradicts an existing and documented one of @IfProfileValue' values, e.g. OR semantic

The code below clearly demonstrate a situation when no matter which test-group's value is set ('all', 'fast', or 'quick') none of the tests will be executed, because the class belongs to a group 'all', but its test methods are from different test groups.

It seems to be a problem in the SpringJUnit4ClassRunner semantic's implementation that a class level @IfProfileValue actually overwrites any method's level @IfProfileValue. Should it have same semantic as as @IfProfileValue's 'values', i.e. with OR semantic, the problem won't exist (see the documentation at http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/test/annotation/IfProfileValue.html)

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({})
@IfProfileValue(name = "test-group", value = "all")

public class MyTests {
  @BeforeClass
  public static void setUp () {
    System.out.println("test-group is set to: " + System.getProperty("test-group"));
  }
  @Test
  @IfProfileValue(name = "test-group", values = {"fast", "quick"})
  public void testOne() {
    System.out.println("testOne(): Quick stuff");
  }

  @Test
  @IfProfileValue(name = "test-group", value = "fast")
  public void testTwo() {
    System.out.println("testTwo(): Fast stuff");
  }
}

Affects: 2.5.6

Issue Links:

Referenced from: commits 2b869d5

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulestatus: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions