1
我想通過AOP向我的testng測試中添加一些通用代碼(例如,將測試的名稱記錄到logback)。下面是我的看點&測試代碼:TestNG和Spring AOP
@Aspect
@Component
public class TestAspect {
...
@Around(value = "execution(* *(..)) && @annotation(org.testng.annotations.Test)")
public Object test(@NotNull final ProceedingJoinPoint pjp) {
...
}}
@ContextConfiguration(classes = { mysample.SpringTestConfigurator.class })
@WebAppConfiguration
public class GlobalTest extends AbstractTestNGSpringContextTests {
...
@Test(enabled = true, priority = 1)
public void testOS() {
...
}}
但看點不叫。哪裏有問題 ?
請分享你的SpringTestConfigurator。您還可以打開彈簧日誌以查看它是否處理與方面相關的任何事情。 – freakman 2014-09-29 09:52:32
SpringTest配置器配置各種東西,如LDAP和屬性。這裏唯一關聯的AOP配置是@EnableAspectJAutoProxy。奇怪的是,其他方面按預期工作,在我看來,AOP並不僅僅適用於測試方法,而是應用於所調用的服務方法。我怎樣才能打開更詳細的彈簧日誌? – kulatamicuda 2014-09-30 07:28:00
取決於您是否使用logback.xml或log4j.properties。在後一種情況下嘗試添加log4j.logger.org.springframework = DEBUG條目 – freakman 2014-09-30 08:23:50