mori– Author –
-
Linux樹林
[Linux] Display the Target of Symbolic Links with the readlink Command
Overview The readlink command is used to find the "actual file path" that a symbolic link (shortcut) points to. While you can check a link's target with ls -l, readlink is better for shell scripts because it outputs only the path itself.... -
Linux樹林
【Linux】readlinkコマンドでシンボリックリンクのリンク先を表示する
概要 シンボリックリンク(ショートカット)が実際に指し示している「実体ファイルのパス」を取得するためのコマンドです。 ls -l でもリンク先を確認できますが、readlink はリンク先パスのみを標準出力するため、シェルスクリプト内で「実行ファイルの絶... -
Linux樹林
[Linux] Create Hard Links and Symbolic Links with the ln Command
Overview The ln command creates "links" to files or directories in the Linux file system. You can create two types of links: "Symbolic Links," which are like Windows shortcuts, and "Hard Links," which allow a single file to have multiple... -
Linux樹林
【Linux】lnコマンドでハードリンク・シンボリックリンクを作成する
概要 Linuxファイルシステムにおいて、ファイルやディレクトリへの「リンク」を作成するコマンドです。 Windowsの「ショートカット」に相当する「シンボリックリンク」と、1つのファイル実体に複数の名前(アクセス経路)を持たせる「ハードリンク」の2種... -
C#樹林
Unit Testing Classes with Dependency Injection in C# using xUnit and Moq
Overview This article explains a unit testing method for classes that use the Dependency Injection (DI) pattern, which is a standard in modern C# development. Instead of directly creating instances of classes that access external service... -
C#樹林
【C#】xUnitとMoqで依存性注入(DI)を利用したクラスの単体テストを作成する方法
概要 モダンなC#開発において標準的な「依存性注入(Dependency Injection: DI)」パターンを採用したクラスの単体テスト手法です。 外部サービスやデータベースへのアクセスを行うクラスを直接インスタンス化せず、インターフェース経由でモックオブジェ... -
未分類
[C#] Testing Class Logic Using Partial Mocks with xUnit and Moq
Overview This article explains "Partial Mocking," a technique using xUnit and Moq to mock only specific methods of a class while keeping the original implementation for the remaining methods. This is effective when there is a need to iso... -
C#樹林
【C#】xUnitとMoqでクラスの一部だけをモック化してテストする(Partial Mock)
概要 xUnitとMoqを使用して、クラスの一部のメソッドだけをモック(偽装)し、残りのメソッドは本来の実装をそのまま動作させる「Partial Mock(部分モック)」の手法です。 乱数生成や現在時刻の取得など、テストのたびに結果が変わる不安定なメソッドだ... -
C#樹林
[C#]Executing Custom Logic during Method Calls with Callback in Moq
Overview This article explains how to execute arbitrary code when a method of a mock object is called using Moq. Beyond just returning a value, the Callback method allows you to define "side effects," such as saving the arguments passed ... -
C#樹林
【C#】Moqでメソッド呼び出し時に独自の処理を実行する(Callback)
概要 Moqを使用して、モックオブジェクトのメソッドが呼び出されたタイミングで任意のコードを実行する方法です。 単に値を返すだけでなく、呼び出された際の引数を変数に保存して後で検証したり、デバッグ用にコンソール出力を行ったりといった「副作用」... -
C#樹林
[C#]Throwing Exceptions with Moq when a Method is Called
Overview Confirming the behavior of "error handling" and "exception cases" is crucial in unit testing. Using the Moq library, you can intentionally throw an exception when a method is called. This allows you to safely test the applicatio... -
C#樹林
【C#】Moqでメソッド呼び出し時に例外を発生させる方法
概要 単体テストにおいて「エラー処理」や「異常系」の動作を確認することは非常に重要です。 Moqライブラリを使用すると、メソッドが呼び出された際に意図的に例外(Exception)を発生させることができます。これにより、例外発生時のアプリケーションの... -
C#樹林
[C#]Defining Argument Conditions and Dynamic Return Values with Moq
Overview This article explains how to define method behavior when using the Moq library for .NET. We will cover three patterns: "Exact Match" which returns a value only for a specific argument, "Conditional Match" which responds to argum... -
C#樹林
【C#】Moqでメソッドの引数条件と動的な戻り値を定義する方法
概要 .NETのモックライブラリ「Moq」を使用して、メソッドが呼び出された際の振る舞いを定義する方法です。 特定の引数が渡された場合のみ値を返す「完全一致」、条件を満たす引数に反応する「条件マッチ」、そして渡された引数を使って計算結果を返す「動... -
C#樹林
[C#]Fixing Return Values and Tracking Property Changes with Moq
Overview This article explains how to define the behavior of interface properties using the Moq library for .NET unit testing. We will cover two patterns: "read-only" behavior that returns a fixed value, and "auto-implemented" behavior t... -
C#樹林
【C#】Moqでプロパティの戻り値固定と値の保持(追跡)を実装する方法
概要 .NETの単体テストにおけるモックライブラリ「Moq」を使用して、インターフェースのプロパティの振る舞いを定義する方法です。 単に値を返すだけの「読み取り専用」のような振る舞いと、値の代入を記憶して保持する「自動実装プロパティ」のような振る... -
C#樹林
Getting Started with Moq in C# (Generating Mock Objects)
Overview "Moq" is a library used in unit testing to separate "external dependencies" such as databases or external APIs. This allows you to verify only the logic of the object you are testing. With Moq, you can easily create "fake object... -
C#樹林
【C#】Moqの利用を開始したい(Mockオブジェクトの生成)
概要 単体テストにおいて、データベースや外部APIなどの「外部依存」を切り離し、テスト対象のロジックだけを検証するために使われるライブラリが「Moq(モック)」です。 Moqを使用すると、インターフェースを実装した「偽物のオブジェクト(Mock)」を簡... -
C#樹林
[C#]Outputting Debug Messages in xUnit.net Unit Tests
Overview When executing tests in xUnit.net, standard Console.WriteLine statements do not display output. Instead, you must receive the ITestOutputHelper interface via the constructor (Dependency Injection) and use its WriteLine method. T... -
C#樹林
【C#】xUnit.netの単体テストでデバッグメッセージを出力する
概要 xUnit.netのテスト実行時には、通常の Console.WriteLine を使用しても出力が表示されません。 代わりに ITestOutputHelper インターフェースをコンストラクタ経由で受け取り(依存性注入)、その WriteLine メソッドを使用することで、テストエクス... -
C#樹林
[C#]Supplying Test Data from External Methods with MemberData in xUnit.net
Overview This implementation uses the [MemberData] attribute in xUnit.net to dynamically supply parameters to test methods from static methods or properties. It is suitable for managing "arrays," "objects," "dynamically generated data," ... -
C#樹林
【C#】MemberData属性でテストデータを外部メソッドから供給する
概要 xUnit.netの [MemberData] 属性を使用し、テストメソッドに渡すパラメータを静的メソッド(またはプロパティ)から動的に供給する実装です。 [InlineData] では扱いにくい「配列」「オブジェクト」「動的に生成されるデータ」や「多数のテストケース... -
C#樹林
[C#]Parameterized Tests Using InlineData in xUnit.net (Data-Driven Testing)
Overview By combining the [Theory] and [InlineData] attributes in xUnit.net, you can execute a single test method multiple times with different input patterns. This is called "Parameterized Testing" or "Data-Driven Testing." It is an eff... -
C#樹林
【C#】InlineData属性を使用したパラメータ化テスト(データ駆動テスト)
概要 xUnit.netの [Theory] 属性と [InlineData] 属性を組み合わせることで、1つのテストメソッドに対して複数の異なる入力パターンを連続して実行できます。 これを「パラメータ化テスト(Parameterized Tests)」または「データ駆動テスト」と呼び、境界... -
C#樹林
[C#]Setup and Teardown in xUnit.net (Constructor and Dispose)
Overview In xUnit.net, a new instance of the test class is created for every test method and destroyed once the test is complete. By utilizing this lifecycle, it is standard practice to write "Setup" in the constructor and "Teardown" in ... -
C#樹林
【C#】xUnit.netでのテスト前処理・後処理(コンストラクタとDispose)
概要 xUnit.netでは、テストメソッドを実行するたびにテストクラスのインスタンスが新しく生成され、終了時に破棄されます。 このライフサイクルを利用して、コンストラクタに「前処理(Setup)」を、IDisposable インターフェースの Dispose メソッドに「... -
C#樹林
[C#]Testing if a Specific Exception Occurs with xUnit.net
Overview This implementation verifies whether a specific exception occurs as expected when a method is executed. Using the Assert.Throws<T> method in xUnit.net, a test succeeds if the specified exception is thrown within the proces... -
C#樹林
【C#】xUnit.netで特定の例外が発生するか検証する
概要 メソッド実行時に期待した通りの例外(エラー)が発生するかをテストする実装です。 xUnit.netの Assert.Throws<T> メソッドを使用すると、内部の処理で指定した例外がスローされればテスト成功、スローされなければ(または違う例外が出れば)... -
C#樹林
Testing if a Value is Within a Specific Range with xUnit.net in C#
Overview This implementation uses the Assert.InRange method in xUnit.net to verify if a test result is between a specific minimum and maximum value (inclusive). It works for integers, dates (DateTime), floating-point numbers, and any typ... -
C#樹林
【C#】xUnit.netで値が指定範囲内に収まっているか検証する
概要 xUnit.netの Assert.InRange メソッドを使用して、テスト結果の値が特定の最小値と最大値の範囲内(境界値を含む)にあるかを検証する実装です。 整数だけでなく、日付(DateTime)や浮動小数点数など、IComparable を実装しているすべての型に対して...