Receber por email
← Voltar para o catálogo

test-equal

When testing Either values, compare the value directly with shouldBe instead of checking isLeft, so test failures show the actual value. Use when writing or reviewing Haskell test code that asserts on Either or similar values.

3estrelas
Atualizado há 4 meses

Ver no GitHub ↗ Licença: Apache-2.0

Como adicionar

/plugin marketplace add ncaq/konoka

O comando exato pode variar conforme o repositório. Confira o README no GitHub.

Para o autor da skill

Cole no README do seu repo

Mostra que sua skill está catalogada na Skillteca, gera backlink e tráfego rastreável.

[![Skillteca](https://www.skillteca.com.br/api/badge/test-equal/svg)](https://www.skillteca.com.br/skills/test-equal)

Skills relacionadas

Ver todas de Desenvolvimento →

Alerta por categoria

Receba novas skills de Desenvolvimento toda segunda

1 email curto, só com as skills novas de Desenvolvimento. 4 minutos de leitura, sem spam, cancela com 1 clique.

Você confirma o email no primeiro envio. Sem spam. Cancela com 1 clique.

Ler descrição completa

テストでの値の比較

Either値をテストするときは値を直接比較する

値xをテストするときに、 値xがEitherの値である場合は、 次のように書くのは避けます。

isLeft x `shouldBe` True

このように書くとテストフレームワーク側に、 実際どのような値が入っていたのかの情報が伝わらないため、 テスト失敗時に情報がなくなってしまいます。

Eitherの値がShowとEqのインスタンスである場合は以下のように単純に比較できます。

x `shouldBe` Left "expected error"

Eqのインスタンスでない場合でも、 isLeftの結果をshouldBeに渡すよりは、 実際の中身の振る舞いを検査できる関数が、 テストフレームワーク側に用意されているはずなので、 それを使うべきです。

Compartilhar X LinkedIn