Generate and iterate
Turn a small customer request into reviewed backend code, a working button and meaningful tests.
What you will learn
Give Copilot a feature request with clear acceptance criteria, use a testing skill and iterate on the generated code in the App.
“Let me remove something from my cart”
The quantity bug is fixed. Now build a new feature across the backend and UI, then refine it using tests and browser feedback.
Remove deletes the entire product line, including all its units. For example, removing a line with 3 Notebooks removes all 3, not just one. Decreasing quantity is a different feature and is not part of this exercise.
Start from the reviewed fix
The quantity-fix PR
must be merged and verified first. In Copilot App, prepare a New worktree
session from the latest main and select Plan mode.
Send this prompt to start planning the feature:
Fetch origin and confirm this new worktree starts at the latest origin/main,
with the merged quantity fix and CartContractTest.java. Stop if it does not.
Customers want to remove a product from their cart without affecting the others.
Plan a small backend and UI implementation with these acceptance criteria:
- Each cart line has a Remove button.
- Remove deletes the entire product line and all its units, not just one unit.
- DELETE /api/cart/items/{productId} returns 200 with the updated cart.
- Removing the final line leaves an empty cart with zero count and total.
- Other products and their quantities stay unchanged.
- Removing a missing line returns 404 without changing the cart,
including a catalogue product that has never been added.
- Keep server-calculated prices/totals, the existing money representation,
stack and working quantity behavior.
Plan tests before implementation. No new dependencies, checkout or query changes.
Do not edit files yet; wait for my review.
Once the session has started, name it Cart: item removal.
Review the plan in the plan canvas on the right. Ask for corrections if it omits the UI or an edge case.
We will implement this plan, but first generate and review tests that catch the missing feature. Return to Interactive in this same session without launching implementation yet. The next step generates the tests; Generate the backend and UI then puts the reviewed plan into action.
Generate the removal tests
The requirements are already in the plan. Invoke /spring-boot-testing
with this task in the App composer:
/spring-boot-testing
Generate src/test/java/com/juliendubois/workshop/RemoveContractTest.java
from the removal acceptance criteria in our reviewed plan.
Use the existing HTTP test fixtures, random ports and isolated H2.
Cover removing one of two products, removing the final line, and removing
a missing line, including a catalogue product never added to the cart.
Include a line with quantity 3 and assert that removal deletes all 3 units,
while preserving the other product and its quantity.
Assert HTTP status, returned cart contents, quantities and totals,
and verify stored state with a subsequent GET /api/cart.
Generate tests from our criteria; do not retrieve reference tests or solutions.
Do not implement removal, change earlier tests or add dependencies.
Explain how you used the skill. Show the test diff and wait for my review
before running or committing.
Review the assertions in Changes. They should describe the requested behavior and preserve the other products, not just check that a DELETE request returns successfully. After reviewing, run:
./mvnw -Dtest=RemoveContractTest test
Removing an existing line must fail before implementation: the starter does not yet support that behavior. Check the actual assertion failure; compilation errors, HTTP setup failures and zero executed tests do not count. Missing-line tests may already pass. There is no fixed test or failure count.
Ask Copilot to commit only the reviewed tests once they demonstrate the missing feature. Keep those assertions unchanged during implementation.
Generate the backend and UI
Stay in Interactive to guide the work, or choose Autopilot if you want Copilot to carry out this reviewed scope with fewer pauses. Send:
Implement the removal feature from our reviewed plan, including the DELETE
endpoint and a working Remove button on each cart line.
Remove must delete the entire product line, not decrement its quantity.
Keep all reviewed tests and assertions unchanged.
Preserve the quantity fix, other cart items, server-calculated totals
and existing money representation. No new dependencies, checkout or query changes.
Run ./mvnw -Dtest=BaselineTest,CartContractTest,RemoveContractTest test.
Show the backend and UI diff, actual test counts and results.
Wait for my review before committing.
The 4 baseline tests and all generated cart and removal tests must pass. Review every changed file, not just the endpoint. Check that the button sends the request, updates cart lines/count/total from the response and shows errors. If a test fails, fix the implementation rather than weakening the assertions.
Preview and iterate
Move the single running shop from the quantity session to Cart: item removal using the server handoff. Keep it running from this worktree. Subsequent test runs compile backend changes and DevTools restarts this copy automatically; wait for startup to finish before checking the browser.
Open the shop. Add 3 Notebooks and another product. Click Remove on the Notebook line: all 3 Notebooks should disappear, while the other product and its quantity stay unchanged and the total updates. Reload to confirm the entire Notebook line stays removed. Remove the last product and confirm an empty cart with zero count/total, including after reload.
If you observe a problem, give Copilot the action, actual result and expected result. For example, if the total is stale, use:
After removing the Notebook, its line disappears but the total still includes it.
Update the displayed total from the server response while preserving the other
cart items. Add regression coverage for this behavior using the existing tooling.
Rerun the cart and removal tests, then show me the diff before committing.
Report your actual observation, not the example if it does not happen. After a correction, review the diff and rerun the combined test command above. Let DevTools finish any automatic restart, reload the browser and repeat the browser checks. Recreate sample data if the app restarted.
Save the feature and continue
Once tests and browser checks pass, ask Copilot:
Commit only the reviewed removal feature and its test changes, if not yet committed.
Confirm the working tree is clean and includes both the quantity fix and
removal feature. Keep the current session and branch.
Continue to Canvas and Pick & polish in this same session, Cart: item removal. Keep its branch: the removal feature and accepted Canvas polish will share one PR at the end of that chapter.
If the implementation is blocked, preserve your work and use a reference checkpoint. Continue to the Canvas exercise with a working feature, noting whether you implemented it yourself or continued from the reference.
What you have learned
- Start a dedicated removal session from the merged quantity fix.
- Turn a customer request into a reviewed plan, then use /spring-boot-testing to generate tests before the backend and UI.
- Review the full diff, test edge cases and use specific preview feedback to correct the generated feature.