micronaut-test icon indicating copy to clipboard operation
micronaut-test copied to clipboard

Using @Property on Junit5 @Test isn't localized

Open vnesek opened this issue 3 years ago • 2 comments

Expected Behavior

When test is annotated with @Property, property value should be localized to specific test instance.

Actual Behaviour

Tests in a suite executed after test with @Property annotation will keep using value from last @Property annotated test executed instead of reverting to default . Makes test results dependent on execution order.

Steps To Reproduce

@Refreshable
class Foo(
    @Property(name =  "foo", defaultValue = "a") val value: String,
)

@MicronautTest
@TestMethodOrder(MethodOrderer.MethodName::class)
class PropertyScopedToTest(
    private val foo: Foo,
) {

    @Test
    fun `1 - should be defaultValue`() {
        assertEquals("a", foo.value)
    }

    @Test
    @Property(name =  "foo", value = "b")
    fun `2 - override by annotation to b`() {
        assertEquals("b", foo.value)
    }

    @Test
    fun `3 - shouldn't this be defaultValue too`() {
        assertEquals("a", foo.value)
    }
}

Environment Information

No response

Example Application

No response

Version

3.3.0

vnesek avatar Feb 08 '22 07:02 vnesek

I hit same issue. Can someone verify please this?

cemo avatar Apr 25 '22 23:04 cemo

Right so I think we would have to shutdown and restart the context if @Property is method level. Same if type level I guess

graemerocher avatar May 10 '22 11:05 graemerocher