2

私のアドバイスは正しく実行されており、2 回実行されていることを除いて正しいアクションを実行しています。一度だけ実行したいです。startTestSuite タイトルがログに 1 回だけ出力されるため、アドバイスをトリガーするはずのメソッドは 1 回だけ実行されます。Bean とコンテキストは TestNG クラスで生成されています。initSpring() メソッドで @BeforeClass および @BeforeSuite タグを使用して実行しようとしましたが、同じ結果が得られました。
さらなるコンテキスト: この目的は、テスト スイートの開始時と終了時のタイムスタンプを取得し、個々のテストの開始時と終了時のタイムスタンプを取得することです。最終的には、テストが失敗したときのスタック トレースをキャプチャして、テストの自動化に最も問題がある場所のパターンを構築し、修正が必要な自動化のより重要な領域に努力を集中できるようにします。些細なことの修正。

ログファイル

[INFO] 2013-02-11 17:56:07.646-0800 test.ui.tests.BVT.initSpring: context object instantiated
[INFO] 2013-02-11 17:56:07.647-0800 test.ui.tests.BVT.initSpring: Shutdown hook registered
[INFO] 2013-02-11 17:56:07.647-0800 test.ui.tests.BVT.initSpring: Obtained a Instrumentation proxy
[INFO] 2013-02-11 17:56:07.661-0800 instrumentation.dao.implement.TestSuiteDaoImpl.beforeTestSuite: ***************Running Advice: beforeTestSuite: startTestSuite
[INFO] 2013-02-11 17:56:07.948-0800 instrumentation.dao.implement.TestSuiteDaoImpl.beforeTestSuite: ***************Running Advice: beforeTestSuite: startTestSuite
[INFO] 2013-02-11 17:56:07.952-0800 test.ui.tests.InstrumentationImpl.startTestSuite: Going to print the title: startTestSuite
[INFO] 2013-02-11 17:56:07.952-0800 test.ui.helpers.TitleLogger.testTitle: ********************
[INFO] 2013-02-11 17:56:07.952-0800 test.ui.helpers.TitleLogger.testTitle: ** startTestSuite **
[INFO] 2013-02-11 17:56:07.953-0800 test.ui.helpers.TitleLogger.testTitle: ********************
[INFO] 2013-02-11 17:56:07.953-0800 test.ui.tests.BVT.initSpring: Called the Proxy

TestNG クラス

public class BVT extends SeleniumTest {    
@BeforeSuite
        public void initSpring() {
            titleLog.testTitle("initSpring");
            context = new FileSystemXmlApplicationContext(new String[]{"spring-beans.xml"});
            Assert.assertNotNull(context, "Unable to load spring-beans.xml");
            logger.info("context object instantiated");
            context.registerShutdownHook();
            logger.info("Shutdown hook registered");
            instrument = (Instrumentation) context.getBean("InstrumentationProxy");
            Assert.assertNotNull(instrument, "Unable to create a Instrumentation Proxy");
            logger.info("Obtained a Instrumentation proxy");
            instrument.startTestSuite();
            logger.info("Called the Proxy");
        }
}

プロキシ用インターフェース

public interface Instrumentation {
    public void startTestSuite();
}

呼び出されたプロキシ メソッド

@Override
    public void startTestSuite() {
        logger.info("Going to print the title: startTestSuite");
        titleLog.testTitle("startTestSuite");   
    }

アドバイス

@Override
    @Before("execution(void test.ui.tests.InstrumentationImpl.startTestSuite())")
    public void beforeTestSuite(JoinPoint jp) {
        logger.info("***************Running Advice: " + jp.getSignature().getName());
        DateTimeHelper dth = new DateTimeHelper();
        TestSuite ts = new TestSuite();

        //Get the current time
        Timestamp start = dth.getCurrentSqlTimestamp();

        //Update the object with the starting time
        ts.setTestSuiteStart(start);

        //Commit to the database
        saveTestSuite(ts);  
    }

spring-beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:component-scan base-package="instrumentation.dao.implement" />
    <context:annotation-config />
    <aop:aspectj-autoproxy /> 

    <bean id="basicDS" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${driver}" />
        <property name="username" value="${username}" />
        <property name="password" value="${password}" />
        <property name="url" value="${url}" />
    </bean>
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="file:datasource.properties" />
    </bean>
    <bean id="testSuite" class="instrumentation.dao.implement.TestSuiteDaoImpl" autowire="constructor" />
    <bean id="Instrumentation" class="test.ui.tests.InstrumentationImpl" />
    <bean id="InstrumentationProxy" 
                 class="org.springframework.aop.framework.ProxyFactoryBean">
        <aop:scoped-proxy proxy-target-class="false"/>
        <property name="target" ref="Instrumentation" />
    </bean>

更新: ポイントカットをこれ (Insturmentation と InstrumentationImpl) に変更したところ、4 回発生しました。

 @Before("execution(void test.ui.tests.Instrumentation.startTestSuite())")

jp.getTarget().toString() を追加したログです。

[INFO] 2013-02-13 14:51:30.258-0800 amazon.omaha.test.ui.tests.BVT.initSpring: context object instantiated
[INFO] 2013-02-13 14:51:30.259-0800 amazon.omaha.test.ui.tests.BVT.initSpring: Shutdown hook registered
[INFO] 2013-02-13 14:51:30.270-0800 amazon.omaha.test.ui.tests.BVT.initSpring: Obtained a Instrumentation proxy
[INFO] 2013-02-13 14:51:30.276-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: *************************************************
[INFO] 2013-02-13 14:51:30.276-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: ** afterTestSuite Advice Method startTestSuite **
[INFO] 2013-02-13 14:51:30.276-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: *************************************************
[INFO] 2013-02-13 14:51:30.276-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: ***********************************************************
[INFO] 2013-02-13 14:51:30.277-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: ** amazon.omaha.test.ui.tests.InstrumentationImpl@cb754f **
[INFO] 2013-02-13 14:51:30.278-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: ***********************************************************
[INFO] 2013-02-13 14:51:30.573-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: *************************************************
[INFO] 2013-02-13 14:51:30.575-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: ** afterTestSuite Advice Method startTestSuite **
[INFO] 2013-02-13 14:51:30.575-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: *************************************************
[INFO] 2013-02-13 14:51:30.576-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: ***********************************************************
[INFO] 2013-02-13 14:51:30.576-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: ** amazon.omaha.test.ui.tests.InstrumentationImpl@cb754f **
[INFO] 2013-02-13 14:51:30.576-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: ***********************************************************
[INFO] 2013-02-13 14:51:30.581-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: ********************
[INFO] 2013-02-13 14:51:30.582-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: ** startTestSuite **
[INFO] 2013-02-13 14:51:30.582-0800 amazon.omaha.test.ui.helpers.TitleLogger.testTitle: ********************
[INFO] 2013-02-13 14:51:30.582-0800 amazon.omaha.test.ui.tests.BVT.initSpring: Called the Proxy
4

1 に答える 1