Tests & Extensions
Add tests and simple extensions to strengthen the REST API.
Tests & Extensions is a free Java Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Intro
Goal: Add tests to validate endpoints and explore small extensions such as search or filtering.
Why test
Why test? Tests protect you when refactoring and ensure REST endpoints work as intended.
Code: JUnit test
A JUnit test checks small units of logic. Here we verify 2+2=4.
import org.junit.jupiter.api.*;public class Main {
@Test
void sampleTest() {
Assertions.assertEquals(4, 2 + 2);
}
}
API testing
Spring Boot allows API tests using MockMvc or WebTestClient. These simulate HTTP calls without a server.
Code: API test simulation
A test can check that GET /tasks returns 200 OK.
// pseudo style, not executable in plain Java
//@Autowired MockMvc mockMvc;
//mockMvc.perform(get("/tasks"))
// .andExpect(status().isOk());
public class Main {
public static void main(String[] args) {
System.out.println("Simulate GET /tasks returns 200 OK");
}
}
Extensions
- Add search endpoint:
GET /tasks?done=true - Support pagination for large lists
- Add validation for empty titles
Testing check
Quick check: Why are automated tests important for a REST API?
Recap
Recap: You saw JUnit basics, simulated API tests, and small API extensions like search and pagination.
Frequently asked questions
Is the “Tests & Extensions” lesson free?
Yes — the full text of “Tests & Extensions” is free to read here on the web, and the Java Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.
What will I learn in “Tests & Extensions”?
Add tests and simple extensions to strengthen the REST API. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Java Academy?
No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Tests & Extensions” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Java Academy lesson?
Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Design
- Implementation
- Tests & Extensions
- Final Recap & Review