Test strategy
22 questions in 8 subtopics.
Test pyramid
What is the test pyramid, and how do Spring Boot slice tests such as@WebMvcTest and @DataJpaTest fit into it?Design a test strategy for a Spring Boot order service that talks to PostgreSQL, Kafka and two HTTP APIs.Your organisation relies on a large, slow end-to-end suite that takes 3 hours and fails often. How would you change the test strategy across teams?Contract testing
What is consumer-driven contract testing, and how do Pact and Spring Cloud Contract differ?Two teams keep breaking each other's APIs despite integration environments. How would you introduce contract testing across 40 services?Over several years, your company moved from a shared integration environment to contract tests between 200 services. What did you gain and lose, and how do you keep the contract system healthy?Mutation testing
What is mutation testing, how does PIT work in a Java build, and what does a surviving mutant tell you?Would you add mutation score as a required quality gate for your organisation? Explain your decision.Property-based testing
What is property-based testing? Describe a property-based test with jqwik for a function that serialises and deserialises an Order.Where would property-based testing add the most value in a payments platform, and where would it not?Test coverage
What is the difference between line coverage and branch coverage in JaCoCo, and why is 100 percent coverage not proof of correctness?Management wants a mandatory 90 percent coverage threshold for all services. How do you respond?Over many years, what has the industry learned about using code coverage as a management metric?Testing legacy code
You need to add a feature to this method with no tests:double price(Order o) {
if (o.items().size() > 10) return o.total() * 0.9;
if (o.customer().isVip()) return o.total() * 0.95;
return o.total();
}
Unit test quality and smells
Review this test and name its smells:@Testvoid test1() {
OrderService s = new OrderService(repo, clock);
Order o = s.create(req);
assertNotNull(o);
verify(repo).save(any());
Thread.sleep(500);
assertTrue(s.findAll().size() > 0);
}
Service virtualization
Using WireMock in a Spring Boot test, stub a payment provider that returns 200 for one card and a 503 with a 2 second delay for another, and point the client at it.Your service depends on six external APIs, and the shared test environment is down half the time. How would you use service virtualization in your test strategy, and what are the risks?Twenty teams each maintain their own stubs for the same core platform APIs, and stubs often disagree with the real behaviour. How do you organise this at the platform level?No question matches these choices.