- Home /
Asynchronous testing with NUnit?
I have a collection subclass who's items remove themselves after some duration:
public class AttrModifierCollection : System.Collections.ObjectModel.Collection<AttrModifier> {
protected override void InsertItem(int index, AttrModifier mod) {
base.InsertItem(index, mod);
if (mod.duration > 0) {
Timer timer = new Timer(mod.duration);
timer.Elapsed += delegate { Remove(mod); };
timer.Start();
}
}
}
I'm trying to write out a test for it but am having a very difficult time.
Here's the test as it currently is:
[Test]
public async void AttrModifier_Temporary()
{
mod = new AttrModifier("test attribute", 20f, 1f);
attribute.modifiers.Add(mod);
Assert.AreEqual(attribute.finalValue, 30f);
Assert.That(attribute.finalValue, IsEqualTo(attrBaseValue).After(2));
}
However, I keep receiving this error:
Unexpected symbol `void' in class, struct, or interface member declaration
If I try removing the void keyword, so that the method declaration is just:
public async AttrModifier_Temporary()
I instead get this error:
CS0246: The type or namespace name `async' could not be found. Are you missing a using directive or an assembly reference?
I can't figure out what's wrong. I'm using Unity 4.3.4f1 on OSX 10.9.3.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613151513im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
MSTools instead of NUnit 0 Answers
Can Unity 5.6's Test Runner optionally output NUnit 2 xml format? 2 Answers
How to prevent Unity from deleting additional Projects in Solution 2 Answers
NUnit delayed constraint does not appear to work in playmode test 0 Answers
Running NUnit test cases on the device 0 Answers