Skip to content

C#コーディング問題(xUnit版) metatest置き換え#50

Draft
Syogo-Suganoya wants to merge 3 commits intocontents/coding-csharp-xunitfrom
contents/coding-csharp-xunit-replace-metatest
Draft

C#コーディング問題(xUnit版) metatest置き換え#50
Syogo-Suganoya wants to merge 3 commits intocontents/coding-csharp-xunitfrom
contents/coding-csharp-xunit-replace-metatest

Conversation

@Syogo-Suganoya
Copy link
Contributor

@Syogo-Suganoya Syogo-Suganoya commented Mar 31, 2023

概要

xUnitを使用したチャレンジを作成しています。
このチャレンジは、顧客企業にチュートリアル用に展開するものです。既存で使用しているmetatestはやや複雑なので、シンプルにxUnit(NUnit)の機能のみで採点されるようにしようとしています。

要件

  • テストタイトルが[hoge] fugaの形式で出力できる
  • 各テスト結果を取得でき、下記の出力ができる
    • pass: ok x ...
    • fail: not ok x ...

ok 1 [基本実装] 入力が 2 と 3 のとき、期待された出力結果が得られる
not ok 2 [基本実装] 入力が 15と 8 のとき、期待された出力結果が得られる
ok 3 [基本実装] 入力が 65 と 94 のとき、期待された出力結果が得られる

関連

#48

@Syogo-Suganoya Syogo-Suganoya self-assigned this Mar 31, 2023
Copy link
Contributor Author

@Syogo-Suganoya Syogo-Suganoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XunitContextNUnitを試してみましたが、動作しませんでした。


Assert.Equal(expected, result);

if (XunitContext.Context.TestStatus == TestStatus.Failed)
Copy link
Contributor Author

@Syogo-Suganoya Syogo-Suganoya Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XunitContext

The type or namespace name 'XunitContext' could not be foundが出力されます。
csprojに<PackageReference Include="XunitContext" Version="3.2.5" />は追加済み。


if (TestContext.CurrentContext.Result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Failed)
{
TestContext.WriteLine("Test failed.");
Copy link
Contributor Author

@Syogo-Suganoya Syogo-Suganoya Mar 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NUnit

標準出力がされないです。

Console.WriteLine("Test failed."); でも同様です。

Copy link
Contributor Author

@Syogo-Suganoya Syogo-Suganoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

簡単にまとめるとこのような状況です。

  • xUnit
    出力ができるが、テスト結果が取得できない
  • NUnit
    出力ができない


Assert.AreEqual(expected, result);

output.WriteLine("This is output from TestMethod");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以前 xunit でテストコード書いたときは TestOutputHelper を使っていました。ご参考になるかわからんですが。

NUnitにTestOutputHelperを入れてみましたが、出力されませんでした。

> sh scripts/test_run.sh
  Determining projects to restore...
  Restored /root/src/src/main/main.csproj (in 2.14 sec).
  Restored /root/src/src/test/test.csproj (in 2.14 sec).

ここまでで出力が終わります。


scripts/test_run.sh の内容

#!/usr/bin/bash
cd /root/src/src/test
dotnet test;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant