csharp-xunit
यह क्या करती है
यह टूल XUnit का इस्तेमाल करके अच्छे कोड टेस्ट लिखने में मदद करता है। XUnit C# प्रोग्राम्स की टेस्टिंग के लिए एक लोकप्रिय library है। यह सरल टेस्ट और अलग-अलग data वाले टेस्ट, दोनों के सबसे अच्छे तरीके सिखाता है।
कब इस्तेमाल करें
- ✓जब आप सुनिश्चित करना चाहते हों कि आपका C# कोड अपेक्षा के अनुसार काम करता है।
- ✓जब ऐसे टेस्ट बनाने हों जिन्हें चलाने के लिए कई data sets चाहिए।
- ✓टेस्ट को साफ़ और दोबारा इस्तेमाल लायक तरीके से व्यवस्थित करना सीखने के लिए।
Skill का लिंक
https://github.com/github/awesome-copilot/blob/main/skills/csharp-xunit/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं XUnit का इस्तेमाल करके 'Add' function के लिए टेस्ट कैसे लिखूँ जो जाँचे कि 2 + 2 = 4 है?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह टूल आपके test project को सेट करने, टेस्ट को व्यवस्थित करने (setup, action और verification को अलग रखकर) और अलग-अलग प्रकार के टेस्ट इस्तेमाल करने के लिए उदाहरण और नियम देता है, जैसे वे टेस्ट जो अलग-अलग data लेते हैं।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
XUnit Best Practices
Your goal is to help me write effective unit tests with XUnit, covering both standard and data-driven testing approaches.
Project Setup
- Use a separate test project with naming convention
[ProjectName].Tests - Reference Microsoft.NET.Test.Sdk, xunit, and xunit.runner.visualstudio packages
- Create test classes that match the classes being tested (e.g.,
CalculatorTestsforCalculator) - Use .NET SDK test commands:
dotnet testfor running tests
Test Structure
- No test class attributes required (unlike MSTest/NUnit)
- Use fact-based tests with
[Fact]attribute for simple tests - Follow the Arrange-Act-Assert (AAA) pattern
- Name tests using the pattern
MethodName_Scenario_ExpectedBehavior - Use constructor for setup and
IDisposable.Dispose()for teardown - Use
IClassFixture<T>for shared context between tests in a class - Use
ICollectionFixture<T>for shared context between multiple test classes
Standard Tests
- Keep tests focused on a single behavior
- Avoid testing multiple behaviors in one test method
- Use clear assertions that express intent
- Include only the assertions needed to verify the test case
- Make tests independent and idempotent (can run in any order)
- Avoid test interdependencies
Data-Driven Tests
- Use
[Theory]combined with data source attributes - Use
[InlineData]for inline test data - Use
[MemberData]for method-based test data - Use
[ClassData]for class-based test data - Create custom data attributes by implementing
DataAttribute - Use meaningful parameter names in data-driven tests
Assertions
- Use
Assert.Equalfor value equality - Use
Assert.Samefor reference equality - Use
Assert.True/Assert.Falsefor boolean conditions - Use
Assert.Contains/Assert.DoesNotContainfor collections - Use
Assert.Matches/Assert.DoesNotMatchfor regex pattern matching - Use
Assert.Throws<T>orawait Assert.ThrowsAsync<T>to test exceptions - Use fluent assertions library for more readable assertions
Mocking and Isolation
- Consider using Moq or NSubstitute alongside XUnit
- Mock dependencies to isolate units under test
- Use interfaces to facilitate mocking
- Consider using a DI container for complex test setups
Test Organization
- Group tests by feature or component
- Use
[Trait("Category", "CategoryName")]for categorization - Use collection fixtures to group tests with shared dependencies
- Consider output helpers (
ITestOutputHelper) for test diagnostics - Skip tests conditionally with
Skip = "reason"in fact/theory attributes
अक्सर पूछे जाने वाले सवाल
unit test क्या है?
यह एक छोटा टेस्ट है जो जाँचता है कि आपके कोड का कोई खास हिस्सा (जैसे कोई function) बाकी कोड से अलग रहकर सही काम करता है या नहीं।
'data-driven' टेस्ट क्या होते हैं?
ये ऐसे टेस्ट होते हैं जो हर बार अलग data सेट के साथ एक ही logic को कई बार चलाते हैं, ताकि ज़्यादा स्थितियों को कवर किया जा सके।
क्या इसे इस्तेमाल करने के लिए C# की बहुत जानकारी चाहिए?
C# और आपका कोड कैसे काम करता है, इसकी बुनियादी समझ होना मददगार है, लेकिन यह टूल टेस्टिंग के सबसे अच्छे तरीकों पर चलने में आपकी मदद करने के लिए बनाया गया है।
जानकारी
लेखक का मूल विवरण
Get best practices for XUnit unit testing, including data-driven tests
repo: github/awesome-copilot
लोकप्रियता
- GitHub स्टार
- 40k
- रैंकिंग में स्थान
- #7156
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
acquire-codebase-knowledge
40kआपके एजेंट को किसी मौजूदा code प्रोजेक्ट को समझने और उसका documentation बनाने में मदद करता है। यह नए लोगों को प्रोजेक्ट से जोड़ने या architecture का सार जानने में उपयोगी है।
acreadiness-assess
40kआपके एजेंट को किसी प्रोजेक्ट की AI के लिए तैयारी जाँचने और रिपोर्ट बनाने देता है। यह समझने में उपयोगी है कि प्रोजेक्ट AI tools इस्तेमाल करने के लिए कितना तैयार है।
acreadiness-generate-instructions
40kआपके एजेंट को assessment के आधार पर AI tools के लिए निर्देश बनाने में मदद करता है। यह बताता है कि AI कोड के साथ बेहतर कैसे काम करे और पहचानी गई कमियाँ कैसे दूर हों।
acreadiness-policy
40kआपके एजेंट को AI प्रोजेक्ट assessment के लिए नीतियाँ तय करने या लागू करने में मदद करता है। यह प्रोजेक्ट्स के मूल्यांकन को मानक बनाने और compliance सुनिश्चित करने में उपयोगी है।
मिलती-जुलती skills
test-driven-development
311kयह आपके एजेंट को किसी भी फ़ीचर या सुधार से पहले पहले असफल होने वाला टेस्ट लिखना, उसे असफल होते देखना, फिर पास करने वाला सबसे छोटा कोड लिखना सिखाती है।
verification-before-completion
311kयह आपके एजेंट को किसी काम, सुधार या build के पूरा या पास होने का दावा करने से पहले असली जांच चलाकर उसका आउटपुट पढ़ना सिखाती है।
migrate-to-shoehorn
310kआपकी टेस्ट फ़ाइलों में जोखिम भरे type casts की जगह shoehorn लाइब्रेरी लगाती है, ताकि टेस्ट अधूरे डेटा से भी type checks पास कर सकें।