CDI + Junit + Wildfly
Bom dia, estou tentando integrar JUnit e CDI em um projeto Web utilizando o servidor de aplicação Wildfly, porém está dando erro na minha classe de teste, já pesquisei e continuo pesquisando a exception, mas decidi postar aqui em paralelo para ver se alguém já passou por esse problema e poderia me ajudar:Classe de teste:
Classe WeldJUnit4Runner:
Exception:
@RunWith(WeldJUnit4Runner.class)
public class PersonServiceTest
{
@Inject
private PersonService service;
public PersonServiceTest()
{
}
@BeforeClass
public static void setUpClass()
{
}
@AfterClass
public static void tearDownClass()
{
}
@Before
public void setUp()
{
}
@After
public void tearDown()
{
}
/**
* Test of savePerson method, of class PersonService.
*/
@Test
public void testSavePerson()
{
System.out.println("savePerson");
Person p = new Person(null, "Person Test", new Date(77, 03, 12));
Person result = this.service.savePerson(p);
assertNotNull(result);
assertEquals(result.getId().longValue(), BigDecimal.ONE.longValue());
// TODO review the generated test code and remove the default call to fail.
}
/**
* Test of getPersons method, of class PersonService.
*/
// @Test
public void testGetPersons()
{
System.out.println("getPersons");
PersonService instance = new PersonService();
List<Person> expResult = null;
List<Person> result = instance.getPersons();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
}
}
Classe WeldJUnit4Runner:
/*
* Project............: JsfCdiJpaJunitIntegration
* Developer..........: Éder Luciano da Costa
* Copyright..........: 2017
* Creation...........: 11/04/2017, 16:04:37
* Codification.......: UTF-8 (Utilizado na criação do arquivo)
* User...............: Éder
* ......................................................................................
* Éder Luciano da Costa - © Copyright 2017 - All Rights Reserved.
* ......................................................................................
*/
package br.com.edersystems.jsfcdijpajunitintegration.conf.junit;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
/**
*
* @author INDRA_E6410_1
*/
public class WeldJUnit4Runner extends BlockJUnit4ClassRunner
{
private final Class<?> classToCreateInstance;
private final Weld weld;
private final WeldContainer container;
public WeldJUnit4Runner(Class<?> classTo) throws InitializationError
{
super(classTo);
this.classToCreateInstance = classTo;
this.weld = new Weld();
this.container = weld.initialize();
}
@Override
protected Object createTest() throws Exception
{
final Object classTest = container.instance().select(classToCreateInstance).get();
return classTest;
}
}
Exception:
org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001334: Unsatisfied dependencies for type PersonServiceTest with qualifiers at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:107) at br.com.edersystems.jsfcdijpajunitintegration.conf.junit.WeldJUnit4Runner.createTest(WeldJUnit4Runner.java:42) at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252) at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141) at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Éder Costa
Curtidas 0