weld / weld-testing

Set of test framework extensions (JUnit 4, JUnit 5, Spock) to enhance the testing of CDI components via Weld. Supports Weld 5.
http://weld.cdi-spec.org/
Apache License 2.0
102 stars 30 forks source link

Field injection not working in 4.0.0.final #145

Closed JGitHub01 closed 2 years ago

JGitHub01 commented 2 years ago

It worked in 2.0.2.final but is broken in 4.0.0.final. Parameter injection still works. I'm using Jakarta ee 8

import javax.enterprise.context.RequestScoped;

@RequestScoped
public class Foo {
  String getMessage() {
    return "Welcome to Weld JUnit5";
  }
}
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.jboss.weld.junit5.WeldInitiator;
import org.jboss.weld.junit5.WeldJunit5Extension;
import org.jboss.weld.junit5.WeldSetup;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import javax.inject.Inject;

@ExtendWith(WeldJunit5Extension.class)
public class FooTest {

  @WeldSetup
  public WeldInitiator weld = WeldInitiator.from(Foo.class).build();

  @Inject
  Foo foo;

  @Test
  public void shouldInjectFieldFoo() {
    assertNotNull(foo);
  }

  @Test
  public void shouldInjectParameterFoo(Foo foo) {
    assertNotNull(foo);
  }
}
manovotn commented 2 years ago

@JGitHub01 this is expected, different versions of this project are for different Jakarta versions:

You'll therefore need to keep using 2.x variant.

JGitHub01 commented 2 years ago

Thanks for clarification.