0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Nablarch-example-restを起動した状態でKarate-Gatlingテストを実行する

Last updated at Posted at 2021-02-16
pom.xml
<dependencies>

    <dependency>
      <groupId>com.intuit.karate</groupId>
      <artifactId>karate-apache</artifactId>
      <version>0.9.6</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.intuit.karate</groupId>
      <artifactId>karate-junit5</artifactId>
      <version>0.9.6</version>
      <scope>test</scope>
    </dependency>

</dependencies>
karatesample.feature
Feature: Karate sample

Background:
Feature: Karate sample

Background:
* url urlBase

Scenario: Get items

Given path "projects"
And header Accept = 'application/json'
When method get
* print response
Then status 200
  And match response == '#[10]'
# resposnse10件
karate-config.js
function() {
  var config = {
      urlBase: 'http://localhost:9080/',
  };
  karate.configure('connectTimeout', 5000);
  karate.configure('readTimeout', 5000);
  return config;
}

Gatling

featureは単体実行もできる。

注意点

  • scalaファイルのパスを指定しないほうが良いtypoでnotfoundexceptionになることがある。
  • nablarchのlocal実行の場合、execute-ddlとload-dataはスキップする
karatesample.feature

  Scenario Outline: get
    Given path 'projects'
    And header <name> = <values>
    And form field clientId = <clientId>
    When method <method>
    * print <exps>
    Then status <status>
    And match $ == '#[1]'
    And match <expression>
    Examples:
      | clientId | name | values          | method | exps     | status | expression                |
      | '1' | Accept | 'application/json' | get    | response | 200    | $[0] contains {"projectName": "プロジェクト001"}|
      | '2' | Accept | 'application/json' | get    | response | 200    | $[0] contains {"projectName": "プロジェクト002"}|
      | '3' | Accept | 'application/json' | get    | response | 200    | $[0] contains {"projectName": "プロジェクト003"}|
      | '4' | Accept | 'application/json' | get    | response | 200    | $[0] contains {"projectName": "プロジェクト004"}|
      | '5' | Accept | 'application/json' | get    | response | 200    | $[0] contains {"projectName": "プロジェクト005"}|
      | '6' | Accept | 'application/json' | get    | response | 200    | $[0] contains {"projectName": "プロジェクト006"}|
      | '7' | Accept | 'application/json' | get    | response | 200    | $[0] contains {"projectName": "プロジェクト007"}|
      | '8' | Accept | 'application/json' | get    | response | 200    | $[0] contains {"projectName": "プロジェクト008"}|
      | '9' | Accept | 'application/json' | get    | response | 200    | $[0] contains {"projectName": "プロジェクト009"}|
      | '10' | Accept | 'application/json' | get    | response | 200    | $[0] contains {"projectName": "プロジェクト010"}|
KarateSimulation.scala
package com.nablarch.example

import com.intuit.karate.gatling.PreDef._
import io.gatling.core.Predef._

import scala.concurrent.duration._

class KarateSimulation extends Simulation {

    val protocol = karateProtocol()

    protocol.nameResolver = (req, ctx) => req.getUrlAndPath()

    val search = scenario("get").exec(karateFeature("classpath:com/nablarch/example/nablarch.feature"))
    setUp(search.inject(
        rampUsersPerSec(0) to 2 during(20 seconds),
        constantUsersPerSec(2) during(40 seconds)
    ).protocols(protocol))
}
pom.xml

    <!-- KARATE-dependency -->
    <dependency>
      <groupId>com.intuit.karate</groupId>
      <artifactId>karate-apache</artifactId>
      <version>0.9.6</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.intuit.karate</groupId>
      <artifactId>karate-junit4</artifactId>
      <version>0.9.6</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.intuit.karate</groupId>
      <artifactId>karate-gatling</artifactId>
      <version>0.9.6</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.gatling.highcharts</groupId>
      <artifactId>gatling-charts-highcharts</artifactId>
      <version>3.0.2</version>
    </dependency>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>2.12.12</version>
      <scope>provided</scope>
    </dependency>
    <!-- KARATE -->

    <!-- KARATE-maven-plugin -->
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>3.4.4</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <args>
                <arg>-Jbackend:GenBCode</arg>
                <arg>-Jdelambdafy:method</arg>
                <arg>-target:jvm-1.8</arg>
                <arg>-deprecation</arg>
                <arg>-feature</arg>
                <arg>-unchecked</arg>
                <arg>-language:implicitConversions</arg>
                <arg>-language:postfixOps</arg>
              </args>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-maven-plugin</artifactId>
        <version>3.1.2</version>
        <configuration>
          <disableCompiler>true</disableCompiler>
        </configuration>
        <executions>
          <execution>
            <phase>test</phase>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?