-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lost active contexts when using static weld #167
Comments
Hello @shishovsa, I took some time debugging this and below are my findings. In your scenario you are using Weld-junit in a
The above lines result in a configured But you are also using a non-static setup to further configure
Now, this code applies further configuration to Maybe I am missing something but the setup you have seems rather weird - I recommend that you change it. You could do one of the following:
|
I understand the underlying issue here is hard to spot for users so I've sent a PR that adds some documentation - #168 |
Thank you @manovotn !
Basically idea was to create abstract test class with all setup: weld, mocks, dockers. To prevent unwanted long-run initialization all services was possibly My trouble is that Thank you again! A bit complex example
public class SettingsManager {
public String getConnectionString(){
return "";
}
}
@RequestScoped
class ServiceFoo {
@Inject
private SettingsManager settingsManager;
void run() {
System.out.println(settingsManager.getConnectionString());
}
}
@ExtendWith(WeldJunit5Extension.class)
abstract class AbstractWeld {
private static final SettingsManager settingsManager = Mockito.mock(SettingsManager.class);
@Inject
protected ServiceFoo serviceFoo;
static {
// docker start
String dockerConnectionString = "str";
// create some mocks
Mockito.when(settingsManager.getConnectionString()).thenReturn(dockerConnectionString);
}
@WeldSetup
public WeldInitiator weldInitiator =
WeldInitiator.from(ServiceFoo.class)
.activate(RequestScoped.class)
.addBeans(MockBean.builder()
.types(SettingsManager.class)
.creating(settingsManager)
.build())
.build();
@AfterEach
void afterEach() {
System.out.println("truncate docker database");
}
}
class ITTestCase1 extends AbstractWeld {
@Test
void doTest1() {
serviceFoo.run();
}
@Test
void doTest2() {
serviceFoo.run();
}
}
class ITTestCase2 extends AbstractWeld {
@Test
void doTest1() {
serviceFoo.run();
}
@Test
void doTest2() {
serviceFoo.run();
}
} |
That should work fine, Weld-junit will look for a singular
It's perfectly fine to have
That really depends on the contents of your test and the complexity to start them. Weld-junit is designed to start a minimal container so on its own it's taking very little time to boot and shouldn't cause you trouble. |
When I using
static
weld object for creatingWeldInitiator
, active contexts was lost after two tests.But when I using
WeldInitiator.from(<classes>)
all tests works fine.The version of weld-junit is 2.0.2.Final, weld is 3.1.9 (Final), junit is 5.4.2.
The text was updated successfully, but these errors were encountered: