Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Whats the strategy for Unit Testing a class which uses a timer?

Whats the strategy for Unit Testing a class which uses a timer?

Scheduled Pinned Locked Moved C#
questiontestingbeta-testingtutoriallearning
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Togakangaroo
    wrote on last edited by
    #1

    After spending the last few months reading about Test Driven Development I am a complete and utter believer. Unfortunately I'm still inexperienced and need advice on unit testing a class which incorporates a timer. For example I am building an ActivityMonitor class which would be used to detect an activity timeout on a class (typically a mediator for a windows form) and reset it. I'm envisioning something like this: ActivityMonitor ..private Timer _timer; ..private EventDelegate _timeout_callback; ..ActivityMonitor(EventDelegate callback, int timer_interval); ..public Reset(); How do I test something like TimeoutRaisesCallback? I could set the timer of course and wait for the callback but that would just slow down my unit tests. Do I merely set it to something very short like a few milliseconds and take the hit? Or is there a better standard way to handle this? Also, suppose I have a class that uses the Activity Monitor: ClassThatUsesActivityMonitor ..private ActivityMonitor _activity_monitor; ..ClassThatUsesActivityMonitor() {_activity_monitor = new ActivityMonitor(new EventDelegate(Reset));} ..public Reset(); ..public DoSomething(); How do I go about unit testing that ClassThatUsesActivityMonitor reacts appropriately if the ActivityMonitor calls its Reset() function while DoSomething() is executing? I look foreward to your responses, thank you very much, Togakangaroo

    T 1 Reply Last reply
    0
    • T Togakangaroo

      After spending the last few months reading about Test Driven Development I am a complete and utter believer. Unfortunately I'm still inexperienced and need advice on unit testing a class which incorporates a timer. For example I am building an ActivityMonitor class which would be used to detect an activity timeout on a class (typically a mediator for a windows form) and reset it. I'm envisioning something like this: ActivityMonitor ..private Timer _timer; ..private EventDelegate _timeout_callback; ..ActivityMonitor(EventDelegate callback, int timer_interval); ..public Reset(); How do I test something like TimeoutRaisesCallback? I could set the timer of course and wait for the callback but that would just slow down my unit tests. Do I merely set it to something very short like a few milliseconds and take the hit? Or is there a better standard way to handle this? Also, suppose I have a class that uses the Activity Monitor: ClassThatUsesActivityMonitor ..private ActivityMonitor _activity_monitor; ..ClassThatUsesActivityMonitor() {_activity_monitor = new ActivityMonitor(new EventDelegate(Reset));} ..public Reset(); ..public DoSomething(); How do I go about unit testing that ClassThatUsesActivityMonitor reacts appropriately if the ActivityMonitor calls its Reset() function while DoSomething() is executing? I look foreward to your responses, thank you very much, Togakangaroo

      T Offline
      T Offline
      Togakangaroo
      wrote on last edited by
      #2

      umm...bump...not sure why I'm not getting a response

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups