|
| 1 | +# JUnit5 TDD Example |
| 2 | + |
| 3 | +## Introduction to JUnit5 |
| 4 | +JUnit5 is the next generation of the JUnit testing framework for Java applications. It provides a modern foundation for developer-side testing on the JVM with powerful features like parameterized tests, dynamic tests, nested test classes, and improved assertions. JUnit5 is compatible with most IDEs, build tools, and CI servers. For more details, visit the [JUnit5 Documentation](https://junit.org/junit5/docs/current/user-guide/). |
| 5 | + |
| 6 | +## Running the Example |
| 7 | +To run the JUnit5 TDD example, execute the `example.sh` script located in `agents/tdd/junit5/`. This script performs the following actions: |
| 8 | +- Clones the target repository: `git clone [email protected]:davidparry/tdd-agent-junit.git` |
| 9 | +- Invokes the `tddjunit5` agent with the specification: `qodo tddjunit5 --set spec="Implement the OddEvenCamp interface requirements from the javadoc for this interface" -y -s` |
| 10 | + |
| 11 | +This sets up and runs the TDD process for implementing the `OddEvenCamp` interface using JUnit5. |
| 12 | + |
| 13 | +## Agent Configuration (agent.toml) |
| 14 | +The `agent.toml` file in `agents/tdd/junit5/` configures the `tddjunit5` agent for executing JUnit5 tests in a Java environment following TDD and BDD principles. Key instructions include: |
| 15 | +- Identifying the project's build system (Gradle or Maven) by checking for specific files like `build.gradle` or `pom.xml`. |
| 16 | +- Creating skeleton classes with stub methods to allow tests to compile. |
| 17 | +- Writing comprehensive JUnit5 test classes that use annotations like `@Test`, `@ParameterizedTest`, `@DisplayName`, and `@Nested`, utilizing features like assertions, parameterized tests with `@ValueSource` or `@CsvSource`, mocks with Mockito, and exception testing with `assertThrows`. |
| 18 | +- Ensuring tests cover basic functionality, exceptions, interactions, and adhere to SOLID principles. |
| 19 | +- Running tests to verify failures (Red phase), with the expectation that implementation will follow to make them pass (Green phase). |
| 20 | +- Providing templates and examples for test structure, test methods, and build configurations. |
| 21 | + |
| 22 | +This configuration guides the agent to produce failing tests first, enforcing TDD practices. |
| 23 | + |
| 24 | +## TDD Example Explanation |
| 25 | +This example demonstrates Test-Driven Development (TDD) using JUnit5. In TDD, development cycles through Red-Green-Refactor phases: |
| 26 | +- **Red**: Write failing tests. |
| 27 | +- **Green**: Implement minimal code to pass the tests. |
| 28 | +- **Refactor**: Improve code while keeping tests green. |
| 29 | + |
| 30 | +Here, the agent creates a skeleton implementation and comprehensive tests for the `OddEvenCamp` interface, which checks if a number is even (return 1) or odd (return 0), throwing `NegativeNumberException` for zero or negative numbers. The tests are designed to fail initially since only stubs are present. This represents the Red phase, where 44 out of 75 tests fail as expected, covering even/odd checks, exceptions, edge cases, and design principles. |
| 31 | + |
| 32 | +## MCP Confluence Setup |
| 33 | + |
| 34 | +This project can be configured to work with a local MCP (Machine-readable Capability Profile) server for Atlassian Confluence. This allows the agent to interact with Confluence for tasks like creating and updating pages. |
| 35 | + |
| 36 | +To use this functionality, you need to set up a Confluence MCP server. You can use any compatible server; for example, one option is available at [https://github.com/aashari/mcp-server-atlassian-confluence](https://github.com/aashari/mcp-server-atlassian-confluence). Follow the setup instructions provided by the MCP server you choose. |
| 37 | + |
| 38 | +Once your server is set up and running, configure the `mcp.json` file in this project to point to it: |
| 39 | + |
| 40 | +**Configure `mcp.json`:** |
| 41 | +Update the `mcp.json` file with the path to your server's entry point and your Atlassian credentials. |
| 42 | + |
| 43 | + ```json |
| 44 | + { |
| 45 | + "mcpServers": { |
| 46 | + "confluence": { |
| 47 | + "command": "node", |
| 48 | + "args": ["/path/to/your/mcp-server-atlassian-confluence/dist/index.js"], |
| 49 | + "env": { |
| 50 | + "ATLASSIAN_SITE_NAME": "your-confluence-site", |
| 51 | + "ATLASSIAN_USER_EMAIL": "[email protected]", |
| 52 | + "ATLASSIAN_API_TOKEN": "your-api-token" |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + ``` |
| 58 | + |
| 59 | + Replace the placeholder values with your specific information. |
0 commit comments