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

Decorator for computed test cases #413

Closed
Nysosis opened this issue Jul 27, 2017 · 5 comments
Closed

Decorator for computed test cases #413

Nysosis opened this issue Jul 27, 2017 · 5 comments

Comments

@Nysosis
Copy link

Nysosis commented Jul 27, 2017

Hi,

Recently came across the desired to be able to specify multiple test cases programmatically (i.e. I had a matrix of combinations I wanted to feed through).

The current @TestCase decorator works great, but AFAIK there's no way to easily specify multiple in that way (there could be, my knowledge of how decorators works is limited).

So what I did was to create a local @TestCases decorator, which was inspired heavily by the @TestCase decorator - except it took an any[][] instead of any[], which allowed me to add multiple items to the TEST_CASES metadata at once.

This allowed me to do something like:

const cases = Array.from(Array(10)).map((_, i) => [i, i * 2])

// ...

@TestCase(...cases)
public FirstIsSecondTimeTwo(first: number, second: number) {
    Expect(second).toBe(first * 2)
}

Obviously a contrived example, but I've found similar functionality very helpful in other unit testing frameworks.

If there's a way of doing it already (native TS/JS or through the library) then point me how and we can close this issue down, otherwise I can either submit a pull request with the decorator I've done and/or we can discuss the interface for specifying computed test cases

@jamesadarich
Copy link
Member

Nice idea @Nysosis,

Might be nice to wrap this up as a decorator that takes a generator specifically for this. What do you think?

@Nysosis
Copy link
Author

Nysosis commented Jul 30, 2017 via email

@jamesadarich
Copy link
Member

I guess if we make it a separate decorator e.g. TestCasesFor or something along those lines there's no reason it couldn't take both? So you can work with whatever suits the situation?

@Nysosis
Copy link
Author

Nysosis commented Jul 30, 2017 via email

Nysosis pushed a commit to Nysosis/alsatian that referenced this issue Aug 10, 2017
Added TestCases decorator, which allows you to specify multiple TestCases via use of an explicit array of cases, generator, or delegate which returns an array of cases or generator
@jamesadarich
Copy link
Member

Closed by #414

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