1. Học hỏi
  2. /
  3. Khoa Học
  4. /
  5. Introduction to Testing in Java

Connected

Bài tập

Unit test: Alerting

In software engineering, it's common to ensure the code runs fast enough by triggering an alert when an operation takes too long to execute. Here, you are given a class called DurationMonitor which depends on an AlertService. When it receives a duration longer than 1 second (1000 milliseconds = 1 second), it triggers an alert on the AlertService.

Verify that the alert indeed triggers for long durations and does not trigger for durations under a second.

Hướng dẫn

100 XP
  • Verify the alertService mock is called for long durations.
  • Verify which method on alertService is called for the example long duration, and with what arguments.
  • Verify in the second test that alertService does not get called.