'How can i initializate a managed bean in a test case for a spring boot web application

i have a problem with the test of a web application. I have this class:

@ManagedBean(name="taxManagedAction")
@RequestScoped
public class TaxManagedAction implements Serializable {
    
@ManagedProperty("#{descriptiveService}")
DescriptiveService descriptiveService;  

public List<NatureVatExemption> acSdiCode(String text) {        
    List<NatureVatExemption> list = descriptiveService.getDescriptive(text);
    return list;
}
}

and i want to test its method. The DescriptiveService is a bean of the application context that can read and write on DB. In the taste case if i try to initializate the class by contructor or with the @Autowired annotation i always have a null object. I try to initializate it via application context, but it is null too. How can i test the class? Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source