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 1 year has passed since last update.

OSS Allure Reportを導入し作成したレポートをブラウザで表示してみる

Posted at

多言語テスト レポート ツールである Allure Report をインストールし使ってみる。

導入先環境

  • CentOS Stream 9

導入パッケージ

  • allure_2.24.1-1.noarch.rpm

結果的に導入したパッケージ

  • sdkman
  • java-17-openjdk
  • zip
  • unzip
  • gradle 8.4

Allureパッケージのインストール

$ sudo rpm -ivh allure_2.24.1-1.noarch.rpm 
エラー: 依存性の欠如:
	java8-runtime | java8-runtime-headless | openjdk8-jre-headless | openjdk-8-jre | openjdk-8-jdk | oracle-java8-installer | oracle-java8-installer は allure-0:2.24.1-1.noarch に必要とされています

下記サイトの「Install via the system package manager (for Linux)」には、特に前提条件の記載が見当たらなかったが、一番下の「Install from an archive (for any system)」には、「Make sure Java version 8 or above installed, and its directory is specified in the JAVA_HOME environment variable.」と記載がある所から、java8以上のインストールが必要そう。

$ sudo yum install -y java-17-openjdk
$ java --version
openjdk 17.0.6 2023-01-17 LTS
OpenJDK Runtime Environment (Red_Hat-17.0.6.0.10-3.el9) (build 17.0.6+10-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.6.0.10-3.el9) (build 17.0.6+10-LTS, mixed mode, sharing)
$ sudo rpm -ivh --nodeps allure_2.24.1-1.noarch.rpm 
Verifying...                          ################################# [100%]
準備しています...              ################################# [100%]
更新中 / インストール中...
   1:allure-0:2.24.1-1                警告: user runner does not exist - using root
警告: user runner does not exist - using root
〜省略〜
警告: user runner does not exist - using root

プロセス起動用ユーザを作成しallure serveで起動

  • --portでポート指定しない場合、起動する毎にランダムでポート番号が変わるため、5050を指定して起動。
$ sudo groupadd allure
$ sudo useradd -g allure allure

# allure を 5050/tcpで起動するので許可ポート設定
$ sudo firewall-cmd --permanent --add-port=5050/tcp
success
$ sudo firewall-cmd --reload
success

$ su - allure
$ export PATH=$PATH:/usr/share/allure/bin
$ allure serve --port 5050
Generating report to temp directory...
allure-results does not exist
Report successfully generated to /tmp/7342712678912309724/allure-report
Starting web server...
2023-11-05 00:24:24.364:INFO::main: Logging initialized @1368ms to org.eclipse.jetty.util.log.StdErrLog
Can not open browser because this capability is not supported on your platform. You can use the link below to open the report manually.
Server started at <http://192.168.11.46:5050/>. Press <Ctrl+C> to exit

ブラウザからアクセス

スクリーンショット 2023-11-05 0.31.23.png

Allure Report に取り込むレポートの作成

  • JUnit5を用いたテストコードの実行結果をレポートとして作成する。
  • 作成に必要な環境は、gradleにて行う。
$ curl -s "https://get.sdkman.io" | bash
〜省略〜
Looking for a previous installation of SDKMAN...
Looking for unzip...
Not found.
======================================================================================================
 Please install unzip on your system using your favourite package manager.

 Restart after installing unzip.
======================================================================================================

'exit 1': command failed with exit code 1.


# unzipパッケージが必要とのことで、rインストール
$ sudo yum install -y unzip
$ curl -s "https://get.sdkman.io" | bash
〜省略〜
Looking for a previous installation of SDKMAN...
Looking for unzip...
Looking for zip...
Not found.
======================================================================================================
 Please install zip on your system using your favourite package manager.

 Restart after installing zip.
======================================================================================================

'exit 1': command failed with exit code 1.


# zipパッケージも必要なようだ
$ sudo yum install -y zip
$ curl -s "https://get.sdkman.io" | bash
〜省略〜
Please open a new terminal, or run the following in the existing one:

    source "/home/allure/.sdkman/bin/sdkman-init.sh"
〜省略〜
$ source .sdkman/bin/sdkman-init.sh 
$ sdk version

SDKMAN!
script: 5.18.2
native: 0.4.3

Gradleのインストール

$ sdk install gradle 8.4
$ gradle -v
〜省略〜


------------------------------------------------------------
Gradle 8.4
------------------------------------------------------------

Build time:   2023-10-04 20:52:13 UTC
Revision:     e9251e572c9bd1d01e503a0dfdf43aedaeecdc3f

Kotlin:       1.9.10
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          17.0.6 (Red Hat, Inc. 17.0.6+10-LTS)
OS:           Linux 5.14.0-319.el9.x86_64 amd64

Gradle定義とテストコード作成

$ vi build.gradle
plugins {
  id 'java'
  id "io.qameta.allure" version "2.11.2"
}

repositories {
  mavenCentral()
}

dependencies {
  testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1'
}

test {
  useJUnitPlatform()
}
$ mkdir -p src/test/java/hello
$ vi ssrc/test/java/hello/HelloTest.java
package hello;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class HelloTest {
  @Test
  public void assertTest() {
    assertEquals(1, 1);
  }
}

Allure Report作成

$ gradle test
$ find build/allure-results/
build/allure-results/
build/allure-results/executor.json
build/allure-results/ace794a7-88b1-4a76-ba0c-a336bc593964-result.json
build/allure-results/e5fac948-38dd-4612-ba72-eafc4f93a219-container.json
build/allure-results/3fe5695c-fa84-4b22-a23c-1208e18e249b-container.json

Allure Reportの生成

$ allure generate build/allure-results -o /tmp/7342712678912309724/allure-report --clean
Report successfully generated to /tmp/7342712678912309724/allure-report

Allure Reportの再表示

gradleで実行したテストコードのメソッド名が表示された。

スクリーンショット 2023-11-05 1.47.58.png

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?