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?

PowerShell Pester の出力を調整したい

0
Last updated at Posted at 2025-10-10

しばらく見ていなかったら様変わりしていて時代の変遷を感じる。

テストファイルとして、こういうのを置いておきます。この辺りは変わらない。

a.Tests.ps1
Describe "テストカテゴリ" {
    It "成功するテスト項目サンプル" {
        1 + 1 | should -be 2
    }

    It "失敗するテスト項目のサンプル" {
        1 + 1 | should -be 3
    }
}

実行するときはこうです。ここも以前と同じ。

# カレントディレクトリ配下の *.Tests.ps1 が実行される
Invoke-Pester

変わったと感じたのは出力のところで、以下のような感じの出力になります。

Starting discovery in 1 files.
Discovery found 2 tests in 44ms.
Running tests.
[-] テストカテゴリ.失敗するテスト項目 16ms (15ms|1ms)
 Expected 2, but got 3.
 at 1 + 2 | should -be 2, C:\temp\pester\a.Tests.ps1:6
 Invoke-Assertion、C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1: 行 8250
 Should<End>、C:\Program Files\WindowsPowerShell\Modules\Pester\5.7.1\Pester.psm1: 行 8189
 (省略)
Tests completed in 160ms
Tests Passed: 1, Failed: 1, Skipped: 0, Inconclusive: 0, NotRun: 0

成功の場合 [+] は非表示で、失敗の場合 [-] はスタックトレースが大量に表示されます。達成感が無いのに威圧感ばかりあってつらい。

ターゲットにするスクリプトの規模が大きくなると、成功が多すぎて使いづらかったのでしょう。小規模界隈は肩身が狭い。

出力の調整をします。

$conf = New-PesterConfiguration

# Fail Fast したい
$conf.run.SkipRemainingOnFailure = "Run"

# 成功も表示して欲しい
$conf.output.Verbosity = "Detailed"

# スタックトレースは冗長すぎるので抑制したい
$conf.output.StackTraceVerbosity = "None"

# 実行
Invoke-Pester -Configuration $conf

こうなります。

Pester v5.7.1

Starting discovery in 1 files.
Discovery found 2 tests in 18ms.
Running tests.

Running tests from 'a.Tests.ps1'
Describing テストカテゴリ
  [+] 成功するテスト項目 4ms (2ms|3ms)
  [-] 失敗するテスト項目 4ms (3ms|1ms)
   Expected 2, but got 3.
Tests completed in 112ms
Tests Passed: 1, Failed: 1, Skipped: 0, Inconclusive: 0, NotRun: 0

嬉しい。

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?