java-junit
यह क्या करती है
यह tool JUnit 5 का उपयोग करके आपके Java कोड के लिए tests लिखने में मदद करता है। यह आम functionalities की testing के सबसे अच्छे तरीके सिखाता है, और अलग-अलग input data वाले tests बनाना भी बताता है।
कब इस्तेमाल करें
- ✓जब आप यह जाँचना चाहते हैं कि आपका Java कोड सही तरीके से काम करता है।
- ✓जब आप अपने प्रोजेक्ट के लिए automated tests लिखना सीख रहे हों।
- ✓कई अलग-अलग input values पर अपना कोड टेस्ट करने के लिए, बिना एक ही कोड बार-बार लिखे।
Skill का लिंक
https://github.com/github/awesome-copilot/blob/main/skills/java-junit/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मैं एक sum function के लिए ऐसा test कैसे लिखूँ जो जाँचे कि 2+2 बराबर 4 होता है?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
यह tool बताता है कि tests को कैसे व्यवस्थित करें, tests को सेट करने और चलाने के लिए JUnit annotations का सही उपयोग कैसे करें, और अपेक्षित परिणाम मिल रहे हैं या नहीं, यह कैसे जाँचें। यह यह भी दिखाता है कि कई स्थितियों में कोड टेस्ट करने के लिए अलग-अलग data sources कैसे इस्तेमाल करें।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
JUnit 5+ Best Practices
Your goal is to help me write effective unit tests with JUnit 5, covering both standard and data-driven testing approaches.
Project Setup
- Use a standard Maven or Gradle project structure.
- Place test source code in
src/test/java. - Include dependencies for
junit-jupiter-api,junit-jupiter-engine, andjunit-jupiter-paramsfor parameterized tests. - Use build tool commands to run tests:
mvn testorgradle test.
Test Structure
- Test classes should have a
Testsuffix, e.g.,CalculatorTestfor aCalculatorclass. - Use
@Testfor test methods. - Follow the Arrange-Act-Assert (AAA) pattern.
- Name tests using a descriptive convention, like
methodName_should_expectedBehavior_when_scenario. - Use
@BeforeEachand@AfterEachfor per-test setup and teardown. - Use
@BeforeAlland@AfterAllfor per-class setup and teardown (must be static methods). - Use
@DisplayNameto provide a human-readable name for test classes and methods.
Standard Tests
- Keep tests focused on a single behavior.
- Avoid testing multiple conditions in one test method.
- Make tests independent and idempotent (can run in any order).
- Avoid test interdependencies.
Data-Driven (Parameterized) Tests
- Use
@ParameterizedTestto mark a method as a parameterized test. - Use
@ValueSourcefor simple literal values (strings, ints, etc.). - Use
@MethodSourceto refer to a factory method that provides test arguments as aStream,Collection, etc. - Use
@CsvSourcefor inline comma-separated values. - Use
@CsvFileSourceto use a CSV file from the classpath. - Use
@EnumSourceto use enum constants.
Assertions
- Use the static methods from
org.junit.jupiter.api.Assertions(e.g.,assertEquals,assertTrue,assertNotNull). - For more fluent and readable assertions, consider using a library like AssertJ (
assertThat(...).is...). - Use
assertThrowsorassertDoesNotThrowto test for exceptions. - Group related assertions with
assertAllto ensure all assertions are checked before the test fails. - Use descriptive messages in assertions to provide clarity on failure.
Mocking and Isolation
- Use a mocking framework like Mockito to create mock objects for dependencies.
- Use
@Mockand@InjectMocksannotations from Mockito to simplify mock creation and injection. - Use interfaces to facilitate mocking.
Test Organization
- Group tests by feature or component using packages.
- Use
@Tagto categorize tests (e.g.,@Tag("fast"),@Tag("integration")). - Use
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)and@Orderto control test execution order when strictly necessary. - Use
@Disabledto temporarily skip a test method or class, providing a reason. - Use
@Nestedto group tests in a nested inner class for better organization and structure.
अक्सर पूछे जाने वाले सवाल
Unit test क्या होता है?
यह एक ऐसा test है जो आपके कोड के एक छोटे हिस्से (आमतौर पर एक function या method) को अलग से जाँचता है, ताकि पक्का हो कि वह अपेक्षा के अनुसार काम करता है।
'Data-driven' tests क्या होते हैं?
ये ऐसे tests हैं जो एक ही test logic को अलग-अलग input और output data के साथ कई बार चलाते हैं। इससे कोड दोहराना नहीं पड़ता।
क्या इसे इस्तेमाल करने के लिए Java की बहुत जानकारी चाहिए?
Java की बुनियादी जानकारी होना मददगार है, लेकिन यह tool testing की बातें साफ़ तरीके से समझाने के लिए बना है, इसलिए शुरुआती लोग भी इसे समझ सकते हैं।
जानकारी
लेखक का मूल विवरण
Get best practices for JUnit 5 unit testing, including data-driven tests
repo: github/awesome-copilot
लोकप्रियता
- GitHub स्टार
- 40k
- रैंकिंग में स्थान
- #7256
- लाइसेंस
- 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 पास कर सकें।