-
Notifications
You must be signed in to change notification settings - Fork 79
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
Dependent Tests, skip some subset of tests if the parent test fails #96
Comments
Dependent tests is a practice that's not usually encouraged since the idea for tests is that they could potentially run in any order. What you can do instead is to use the |
^ With this you can do something like g.Describe("Board")
g.BeforeEach(func() {
// Create new board here before each test
})
g.AfterEach(func() {
// Cleanup created board.
})
g.It("should be created with params xxx") // Test that creates a new board
g.It("should be fetched by id") // Fetch the board created in the beforeEach function
..... Makes sense? If creating and destroying the board before each |
Hmm, thanks for the suggestion... Re: BeforeEach/AfterEach - I am already having issues (429) with hitting my limits on API calls while running tests, so I think I will try to do my best to work with one set of prerequisites for the entire "type" instead of creating/deleting them foreach. Re: Before/After - I am already attempting to do that to create the prerequisites for the deeper tests... for example: https://github.com/TJM/go-trello/blob/master/card_test.go#L39-L54 ... but I don't think it really likes the assertions I put into the before ;) The "structure" is something like: trello.Client:
member:
board:
- list:
- card:
- checklist:
- item ... so, for example, in order to test "card" (SetName, SetDescription, AddMember, etc), you need to have a working client, board, and card. I have each of those in the "before" ... maybe it just comes down to having the tests in the wrong place, but it seems crazy to not test checklist items while you have just created a checklist, rather than to tear it all down and build it in another file. |
It would be nice to have the ability to indicate dependent tests in order to "skip" them when their prerequisite test fails. However, I re-arranged my tests so that the g.Before() lays out all the pre-requisites for that test. I guess that comes down to a "code organization" thing.. I am "new" to go... obviously. :) The previous developer (that I forked from) chose to put "CreateBoard" into the "board.go" instead of the "client.go" even though it starts with Thanks, |
OK, new question... How do you "fail" the I have the following error:
... so it did "sorta" work, in that all the other tests didn't try to run, but as I said before, it doesn't like assertions in the g.Before... what is the proper way to "fail" or can we make it so that g.Before can have assertions? |
Perhaps I am just not searching for the right terms, so I am going to try to explain what I am trying to accomplish...
I am currently adding tests to github.com/TJM/go-trello and I have hit a conditions multiple times where tests need to depend on the previous test. For example:
(etc)
If "Create Board" fails, the other two need to "skip" or "fail fast" or something, but currently it just blows up and I get the go equivalent of a null pointer exception.
I was thinking of adding an assertion at the top, which should cause the test to fail at least (better than the crash I was getting before), but the failure state would look better if it showed them as dependent tests that were skipped :-/
The text was updated successfully, but these errors were encountered: