用于自定义注释和其方面的单元测试

时间:2018-07-11 14:54:20

标签: java spring junit mockito aspectj

我已经创建了一个自定义注释,并在其上写了一个方面:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Alert {
    public enable() default true;

}

这是它的方面:

@Aspect
@Component
public class AlertAspect {
    @Around("@annotation(Alert)")
    //something
    return joinPoint.proceed();
    //something
}

这两个文件位于src / main / java / project /包中。

现在我必须在src / test / java / project包中编写测试用例。 我该怎么办,我尝试创建应用程序配置文件(AlertTest-config.xml),并在其中添加了这些行。

<context:annotation-config/>
    <context:component-scan base-package="project">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/>
</context:component-scan>
<aop:aspectj-autoproxy />
<bean id="alertAspect" class ="project.AlertAspect"/>

并在Test类上使用了这两个注释

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:project/AlertTest-config.xml"})
public class AlertTest{
    @Alert
    public void testMethod(){
    }
}

但这不会pi注释,并且也没有在其上运行任何方面。

0 个答案:

没有答案