Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to include more data in an assertion. #79

Open
BenjaminSchaaf opened this issue Mar 24, 2018 · 4 comments
Open

A way to include more data in an assertion. #79

BenjaminSchaaf opened this issue Mar 24, 2018 · 4 comments

Comments

@BenjaminSchaaf
Copy link
Contributor

BenjaminSchaaf commented Mar 24, 2018

When you have a test that needs to run multiple times, or simply includes an iteration of some sort, it is often useful to know at which iteration an assertion failed. Currently the only way to include that data with because:

unittest {
    foreach(i; 0..100) {
        ...

        result.should.equal(expected).because("At iteration %s".format(i));
    }
}

It would be nice if there was a simple way of including arbitrary data along with an exception, maybe something like this:

result.should.equal(expected).with(i);

----------------------
TestException: result should equal expected.
i = 5

Expected: ...

Or perhaps a middle-ground would be to allow because to be used like format:

result.should.equal(expected).because("At iteration %s", i);
@gedaiu
Copy link
Owner

gedaiu commented Mar 24, 2018

this is an interesting topic... depending on your problem, there are multiple solutions.

one way around this for your example would be this one:

static foreach(i; 0..100) {
    unittest {
        ...

        result.should.equal(expected).because("At iteration %s".format(i));
    }
}

another way is a soft assertions support, which I would like to add in the future... I'm not sure about the syntax...

@BenjaminSchaaf
Copy link
Contributor Author

The issue with that workaround is that each "test" needs to happen serially, as I'm using a test runner that runs tests in parallel. What do you mean by software assertions?

@gedaiu
Copy link
Owner

gedaiu commented Mar 24, 2018

sorry ... it was a typo :P I was reffering to soft assertions the idea would be to add a bunch of assertions and evaluate them at the end of the test,

maybe this is not the best reference, but it is a way of doing it:
https://github.com/Magenic/MAQS/wiki/Soft-Asserts

@gedaiu
Copy link
Owner

gedaiu commented Mar 24, 2018

oh... sorry. I think I misunderstood your problem. I think I get it now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants