Loading...
Loading...
A specialized skill for test naming conventions and best practices. Use this when you need to name test methods, improve test readability, or establish naming standards. It covers three-part naming method, Chinese naming recommendations, test class naming, etc. Keywords: test naming, test naming, naming conventions, naming conventions, three-part naming, three-part naming, method_scenario_expected, method_scenario_expected, how to name tests, test readability, test readability, naming best practices, test reports, test documentation
npx skill4agent add kevintsengtw/dotnet-testing-agent-skills dotnet-testing-test-naming-conventions[TestedMethodName]_[TestScenario/InputCondition]_[ExpectedBehavior/Result]| Section | Description | Example |
|---|---|---|
| Tested Method Name | Name of the method being tested | |
| Test Scenario/Input Condition | Describes test preconditions or inputs | |
| Expected Behavior/Result | Describes expected output or behavior | |
| ❌ Bad Name | ✅ Good Name | Reason |
|---|---|---|
| | Clearly states test scenario and expected result |
| | Meaningful description |
| | Complete three-part naming |
| | Clear exception scenario |
// ✅ 正常路徑測試
[Fact]
public void Add_輸入1和2_應回傳3()
// ✅ 邊界條件測試
[Fact]
public void Add_輸入0和0_應回傳0()
// ✅ 負數測試
[Fact]
public void Add_輸入負數和正數_應回傳正確結果()// ✅ 有效輸入測試
[Fact]
public void IsValidEmail_輸入有效Email_應回傳True()
// ✅ 無效輸入 - null
[Fact]
public void IsValidEmail_輸入null值_應回傳False()
// ✅ 無效輸入 - 空字串
[Fact]
public void IsValidEmail_輸入空字串_應回傳False()
// ✅ 無效輸入 - 格式錯誤
[Fact]
public void IsValidEmail_輸入無效Email格式_應回傳False()// ✅ 處理流程測試
[Fact]
public void ProcessOrder_輸入有效訂單_應回傳處理後訂單()
// ✅ 例外處理測試
[Fact]
public void ProcessOrder_輸入null_應拋出ArgumentNullException()
// ✅ 格式化測試
[Fact]
public void GetOrderNumber_輸入有效訂單_應回傳格式化訂單號碼()// ✅ 正常計算
[Fact]
public void Calculate_輸入100元和10Percent折扣_應回傳90元()
// ✅ 無效輸入 - 負數
[Fact]
public void Calculate_輸入負數價格_應拋出ArgumentException()
// ✅ 邊界值測試
[Fact]
public void Calculate_輸入0元價格_應正常處理()
// ✅ 含稅計算
[Fact]
public void CalculateWithTax_輸入100元和5Percent稅率_應回傳105元()// ✅ 初始狀態測試
[Fact]
public void Increment_從0開始_應回傳1()
// ✅ 連續操作測試
[Fact]
public void Increment_從0開始連續兩次_應回傳2()
// ✅ 重設測試
[Fact]
public void Reset_從任意值_應回傳0()[TestedClassName]Tests| Tested Class | Test Class Name |
|---|---|
| |
| |
| |
| |
namespace MyProject.Tests;
/// <summary>
/// class CalculatorTests - Calculator 測試類別
/// </summary>
public class CalculatorTests
{
private readonly Calculator _calculator;
public CalculatorTests()
{
_calculator = new Calculator();
}
//---------------------------------------------------------------------------------------------
// Add 方法測試
[Fact]
public void Add_輸入1和2_應回傳3()
{
// ...
}
//---------------------------------------------------------------------------------------------
// Divide 方法測試
[Fact]
public void Divide_輸入10和2_應回傳5()
{
// ...
}
}[Theory]// ✅ 使用「各種」表示多組測試資料
[Theory]
[InlineData(1, 2, 3)]
[InlineData(-1, 1, 0)]
[InlineData(0, 0, 0)]
public void Add_輸入各種數值組合_應回傳正確結果(int a, int b, int expected)
// ✅ 使用「有效」表示正向測試
[Theory]
[InlineData("test@example.com")]
[InlineData("user.name@domain.org")]
public void IsValidEmail_輸入有效Email格式_應回傳True(string validEmail)
// ✅ 使用「無效」表示負向測試
[Theory]
[InlineData("invalid-email")]
[InlineData("@example.com")]
public void IsValidEmail_輸入無效Email格式_應回傳False(string invalidEmail)| Vocabulary | Usage Scenario |
|---|---|
| General input parameters |
| Given-When-Then style |
| Event trigger |
| Initial state description |
| Vocabulary | Usage Scenario |
|---|---|
| Has return value |
| Expected exception |
| State verification |
| Collection verification |
| Boundary conditions |
Method_Scenario_ExpectedTest1TestMethod✅ CalculatorTests
✅ Add_輸入1和2_應回傳3
✅ Add_輸入負數和正數_應回傳正確結果
❌ Divide_輸入10和0_應拋出DivideByZeroException
✅ EmailHelperTests
✅ IsValidEmail_輸入有效Email_應回傳True
✅ IsValidEmail_輸入null值_應回傳False