Skip to content

Instantly share code, notes, and snippets.

@paulmilner
Last active August 29, 2015 14:16
Show Gist options
  • Save paulmilner/90f2e258c14715333e4c to your computer and use it in GitHub Desktop.
Save paulmilner/90f2e258c14715333e4c to your computer and use it in GitHub Desktop.
How to set up a Weld test
/*
Weld dependency for your POM:
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>Whatever the latest version is!</version>
</dependency>
*/
//The Application under test:
public class Application {
@Inject
String thing;
public boolean isInitialised() {
return true;
}
}
//For the test
public class WeldTest {
static WeldContainer container;
@BeforeClass
public static void setupClass() throws Exception {
Weld weld = new Weld();
container = weld.initialize();
}
@Test
public void application_initializes_ok throws Exception {
Application app = container.instance().select(Application.class).get();
assertTrue(app.isInitialised()); //although the test would've failed anyway if injection failed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment