1

I have some code that looks like this

[Test, TestCaseSource("NspecRunner")]
public void TextContext (example thing)
  {
     //does testing like things using thing
     while( othread.threadState == running && currentTestCount == StaticList.count)
          Thread.Sleep(1000)
  }

public List<example> NspecRunner
{
    ClassName x = new ClassName
    Thread othread = new Thread(new ThreadStart(() => x.function_that_adds_to_StaticList()));
    return ClassName.StaticList;
}

However Nunit doesn't ever look at the StaticList that is being returned after the initial look. Do you know of any way to make the TestCaseScenario reevaluate so that it will create a new test as the other thread adds new stuff to that static class. I'm totally open to other frameworks. Or if you know where in the Nunit project I can find a way to modify the way that TestCaseSource works, that would be lovely.

edit: I'm trying to create a test for each item inside of ClassName.StaticList. I don't know how many are going to be in the list, but I would like each test to start immediately after the item is added to the StaticList by the other thread. Is that possible?

DrSammyD
  • 880
  • 12
  • 32
  • It might help to know a more specific scenario of what you're trying to test. I'm just having a hard time following the goal of this. – Chris Missal Sep 21 '12 at 00:52
  • I just made an edit explaining my goals. – DrSammyD Sep 21 '12 at 01:45
  • 1
    Do you mean that the unit test should wait for new items to be added to `ClassName.StaticList`? `StaticList` is `static`; couldn't `function_that_adds_to_StaticList()` also be `static`? And would it be possible for you to wait for the threads to finish before you return your updated `StaticList`? – Anders Gustafsson Sep 21 '12 at 05:45
  • Yes, StaticList is a static member of ClassName. As for waiting for the thread to finish, that's what I'm currently doing, but I'd like to see the results of the test as they become available. I'm wondering if that is possible. And no, function_that_adds_to_StaticList() isn't actually a function that I own, though you have given me an idea. I'll let you know if it works. – DrSammyD Sep 21 '12 at 13:16

0 Answers0