Skip to content

Writing a unit test in xunit that passes if a function call takes too long #217

@mattqs

Description

@mattqs

I asked a question in stackoverflow http://stackoverflow.com/q/27220254/1109316 about passing a test after timeout.

Maybe there could be an attribute that makes writing these tests easier?

Instead of:

 [Fact]
 public void WrongServerKey()
 {
    bool flag = false;
    Task.Run(() =>
    {
        var result = CallServerWithWrongKey();
        flag = true;
    });
    Task.Delay(TimeSpan.FromSeconds(5)).Wait();
    Assert.False(flag);
 }

Something like:

 [Fact (Timeout = 8000,PassTimeout = true)]
public void WrongServerKey()
{
        var result = CallServerWithWrongKey();
}

This test should fail if it reaches the end before the timeout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions