CS FundamentalsHardProduct-company placement
A unit test calls a service that reads the current time with datetime.now() and fails every day after 6 pm. What is the cleanest fix?
- A. Run the tests only in the morning
- B. Inject a clock (or a time-provider function) into the service, so tests can pass a fixed time
- C. Add a sleep until 9 am in the test
- D. Mark the test as flaky and ignore it
Correct answer: B. Inject a clock (or a time-provider function) into the service, so tests can pass a fixed time
Hidden dependencies on time, randomness or the network make tests non-deterministic. Passing them in as dependencies lets tests control them - the same idea as dependency injection.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- How many of these situations can produce a merge conflict when merging branch B into A from their common ancestor O? 1. A and B changed…
- Feature X takes the 'happy path' through 5 screens. An alternate flow can occur at screen 2 (2 variants) and an exception flow at screen 4…
- A mobile app shows the error rate of a new release, rolled out to 10% of users as a canary, at 1.2% against 0.4% for the old version on…
- Assertion (A): A test suite that mocks every collaborator of every class can pass while the integrated system fails. Reason (R): Mocks…
- A single-page app makes 30 sequential API calls to render a dashboard, each taking about 40 ms of network round trip. The team cannot…
- A Scrum team's velocity over 6 sprints was 20, 22, 35, 21, 23 and 19 points; sprint 3 included a one-off batch of over-estimated stories…