0
0
Testing Fundamentalstesting~20 mins

Contract testing basics in Testing Fundamentals - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Contract Testing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary purpose of contract testing?

Imagine two teams working on different parts of a software system. One team builds a service (provider), and the other builds a client (consumer) that uses that service. What is the main goal of contract testing between these two teams?

ATo ensure the provider service has no security vulnerabilities.
BTo test the entire system end-to-end including all external dependencies.
CTo verify that the provider and consumer agree on the data format and interaction rules.
DTo check the user interface responsiveness under load.
Attempts:
2 left
💡 Hint

Think about what needs to be agreed upon between two separate parts that communicate.

Predict Output
intermediate
2:00remaining
What is the output of this contract test result?

Given this simplified contract test result output, what does it indicate?

Testing Fundamentals
Contract Test Result:
Consumer: OrderApp
Provider: PaymentService
Test: PaymentService accepts order payment request
Result: FAIL
Error: Expected field 'amount' to be a number but got string
AThe consumer sent a wrong request format, but the provider responded correctly.
BThe provider returned a string instead of a number for 'amount', causing the test to fail.
CThe test passed successfully with no errors.
DThe provider service is down and did not respond.
Attempts:
2 left
💡 Hint

Look at the error message carefully about the 'amount' field type.

assertion
advanced
2:00remaining
Which assertion correctly verifies a contract response field type?

You want to write an assertion in your contract test to check that the provider's response field status is a string with value 'success'. Which assertion is correct?

Aassert response['status'] == 'success' and isinstance(response['status'], str)
Bassert response.status == 'success' or isinstance(response.status, str)
Cassert response['status'] = 'success' and type(response['status']) == 'string'
Dassert response['status'] == 'success' and type(response['status']) == str
Attempts:
2 left
💡 Hint

Remember Python syntax for assertions and type checking.

🔧 Debug
advanced
2:00remaining
Why does this contract test fail with a KeyError?

Review this contract test snippet and identify why it raises a KeyError:

Testing Fundamentals
response = provider.get_order(123)
assert response['orderId'] == 123
assert response['total'] > 0
assert response['status'] == 'confirmed'
AThe 'total' field is a string, so comparison with 0 causes TypeError.
BThe 'orderId' key is misspelled in the assertion.
CThe provider.get_order method returns None, so indexing fails.
DThe response dictionary does not contain the key 'status', causing KeyError.
Attempts:
2 left
💡 Hint

Check which keys are accessed and whether they exist in the response.

framework
expert
2:00remaining
Which contract testing framework supports consumer-driven contracts with automatic verification?

You want to implement consumer-driven contract testing where the consumer defines the contract and the provider verifies it automatically during CI. Which framework is best suited for this?

APact
BSelenium
CJUnit
DPostman
Attempts:
2 left
💡 Hint

Look for a framework specialized in contract testing between services.