{
"title": "セットアップ - xUnit.net",
"useMathjax": false
}
================================================================================
テスト対象となるプロジェクトのプロジェクト名 + .Tests が多いテストプロジェクトに xUnit.net をインストールする
Visual Studio のメニューバーから ツール → NuGet パッケージマネージャ → ソリューションのパッケージの管理 を開く
ダイアログ右側からオンライン nuget.org を選ぶ
左上にある検索ボックスに xUnit.net と入力して検索
検索結果の中にある xUnit.net と xUnit.net [Runner: Visual Studio] をテストプロジェクトにインストールする

internal 属性にアクセスしたい場合は、テスト対象となるプロジェクトの AssemblyInfo.cs に以下を追記する[assembly: InternalsVisibleTo("『テストプロジェクトのアセンブリ名』")]
テスト対象のクラス名 + Tests が多いテスト対象のメソッド名 + Test が多いFact 属性をつけるusing Xunit;
public class IntCalculatorTests
{
[Fact]
public void AddTest()
{
Assert.Equal(0, IntCalculator.Add(0, 0));
Assert.Equal(1, IntCalculator.Add(0, 1));
Assert.Equal(1, IntCalculator.Add(1, 0));
Assert.Equal(2, IntCalculator.Add(1, 1));
}
}
テストを実行 を選択テストを実行 を選択テスト → 実行 → 全て を選択テスト → ウィンドウ → テスト エクスプローラー を選択する。)