iT邦幫忙

DAY 25
0

初探網站自動化測試系列 第 25

整合 Spira Test 之一 (Geb Day 25)

  • 分享至 

  • xImage
  •  

我目前使用的framework是Geb + Spock

我們需要TestSetId、TestCaseId 這兩個變數,才能將資料匯入Spira Test中,但 Spira Test 並沒有提供Spock的擴充API。

變通的辦法是Maven surefire會產出符合JUnit的報表格式,而Spira Test有提供 Extension For JUnit Automated Testing Framework,雖然並沒有完全符合我的需求,但其他部分可自行實作補足。

* SpiraTestCase

@java.lang.annotation.Target({java.lang.annotation.ElementType.TYPE})
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@org.spockframework.runtime.extension.ExtensionAnnotation(SpockExtension.class)
public @interface SpiraTestCase {
    public int id() default 0;
}

* SpiraTestSet

@java.lang.annotation.Target({java.lang.annotation.ElementType.TYPE})
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@org.spockframework.runtime.extension.ExtensionAnnotation(SpockExtension.class)
public @interface SpiraTestSet {
    public int id() default 0;
}

* SpockExtension

import org.spockframework.runtime.extension.AbstractAnnotationDrivenExtension;

public class SpockExtension extends AbstractAnnotationDrivenExtension {

    public void visitSpecAnnotation(java.lang.annotation.Annotation annotation, org.spockframework.runtime.model.SpecInfo spec) { /* compiled code */ }

    private void sortFeaturesInDeclarationOrder(org.spockframework.runtime.model.SpecInfo spec) { /* compiled code */ }

    private void includeFeaturesBeforeLastIncludedFeature(org.spockframework.runtime.model.SpecInfo spec) { /* compiled code */ }

    private void skipFeaturesAfterFirstFailingFeature(org.spockframework.runtime.model.SpecInfo spec) { /* compiled code */ }
}

* SpiraIntegrationListener

public class SpiraIntegrationListener extends RunListener{
    private Integer getSpiraTestCaseId(Description description){
        Class<?> obj = description.getTestClass();

        if (obj.isAnnotationPresent(SpiraTestCase.class)) {
            Annotation annotation = obj.getAnnotation(SpiraTestCase.class);
            SpiraTestCase spiraTestCase = (com.inflectra.spiratest.addons.junitextension.spock.SpiraTestCase) annotation;
            return spiraTestCase.id();
        }
        return 0;
    }
}

* pom.xml

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.9</version>
        <configuration>
          <includes>
              <include>*Spec.*</include>
          </includes>
          <systemPropertyVariables>
            <geb.env>chrome</geb.env>
            <geb.build.baseUrl>http://127.0.0.1</geb.build.baseUrl>
            <geb.build.reportsDir>target/test-reports/geb</geb.build.reportsDir>
          </systemPropertyVariables>
            <properties>
                <property>
                    <name>usedefaultlisteners</name>
                    <value>false</value>
                </property>
                <property>
                    <name>listener</name>
                    <value>com.inflectra.spiratest.addons.junitextension.SpiraIntegrationListener</value>
                </property>
            </properties>
        </configuration>
      </plugin>

* GebReportingSpec

@Stepwise
@SpiraTestCase(id=123)
@SpiraTestSet(id=1)
class FaqSpec extends GebReportingSpec

上一篇
整合至 CI server 之四 (Geb Day 24)
下一篇
整合 Spira Test 之二 (Geb Day 26)
系列文
初探網站自動化測試30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言