.net - MonoTouch testing of threads -


i have class functions in different thread. want test class in monotouch app. added test fixture test projects. found monotouch not wait test finish, says "successful" while test case still running. example of case below:

[test] public void threadtest() {     timer applicationtimer = new timer {enabled = true, interval = 2500};     applicationtimer.elapsed += applicationtimer_tick; }  private void applicationtimer_tick (object sender, elapsedeventargs e) {    assert.fail("failing"); // time debugger hits point, ui says tests passed. totally wrong.  } 

any appreciated.

this not monotouch specific issue - test fail in testrunners.

a test waits async event might like:

        private manualresetevent _mre = new manualresetevent(false);          [test]         public void threadtest()         {             timer applicationtimer = new timer {enabled = true, interval = 2500};             applicationtimer.elapsed += applicationtimer_tick;             if (!_mre.waitone(3000))             {                 assert.fail("timer not signalled");             }         }          private void applicationtimer_tick (object sender, elapsedeventargs e)         {             _mre.set();                      } 

but you'd have careful in writing sort of test make sure didn't lock threads, reuse objects across tests, etc.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -