Comments (5)
Agreed with above.
And of course you should be able to use asserts in tearDown but in my opinion those asserts should just check that things have been cleaned nicely for the next setUp / test cases to be run. Thus, tearDown cleans the things that have been setup in setUp, nothing more. If a test does some more initialization, then it is the respobsibility of a test to do the cleanup, not the tearDown.
What about inroducing a new macro TEST_IGNORE_NO_TEARDOWN() if current functionality needs to be supported.
from unity.
There are a number of users who put assertions in their tearDown functions. This creates a
challenging flow:
...
There might be a good reason to do this, but personally I don't see it. Also, if an assertion fails in teardown because the test was not run I think there is something wrong with the test design.
I think the correct thing would be to not run setup() if the test is ignored. But it seems difficult with the current design. Otherwise I think the user should be responsible for designing the test cases correctly. Maybe there is a way to improve the output so that the mistake is obvious.
from unity.
:) Yeah, this is a topic that comes up from time to time. We've reversed the way this works a number of times. Here's the problem: There are a number of users who put assertions in their tearDown functions. This creates a challenging flow:
setup is run
the test is run: encountering an IGNORE statement, it immediately leaves
tearDown is run: encountering a failing assertion, it now flags the test as a failure and aborts the tearDown.
The solution would be to have every assertion double-check if there is an ignore in effect, but this is a lot of additional overhead for a weird corner case.
We've talked about expanding the options for functions... something like:
setUp - for memory initialization, etc... no assertions here
preTest - run before each test. assertions allowed here
(test)
postTest - run after each test. assertions allowed here. only run when test passed.
tearDown - run after each test. no assertions here. always run
There are a few downsides:
(1) on many platforms, these are just more functions that someone has to define in order to use the tools... they have no intention of actually using them. (yuck, boilerplate!)
(2) there's not really a way to enforce the no-assertion rules... or at least not without additional overhead in each assertion call.
(3) I threw out some names above... but adding two more functions to an already confusing naming scheme isn't going to clear things up, most likely. ;)
Anyway, that's what we're up against here. Thoughts? I'd love to get more opinions.
Mark
from unity.
@mvandervoord commented
The solution would be to have every assertion double-check if there is an ignore in effect
It appears this check happens already. UNITY_SKIP_EXECUTION
bypasses all asserts when ignored.
(BTW, could we change the name of that macro to be more descriptive? I can open another issue. #239 Name changed to RETURN_IF_FAIL_OR_IGNORE
)
The flow:
If Unity ignore didn't skip teardown, all tearDown()
code would be run except assertions' internals, which would not fail.
This feels like the best choice to me. I tried it out, and all tests still passed. This includes one test that calls a failing TEST_ASSERT in teardown.
I can provide a PR.
from unity.
I move to close - issue resolved in above PR.
from unity.
Related Issues (20)
- Bug: Boolean is found to be both true and false simultaneously HOT 3
- No mention about instructions to build from source and support_double option HOT 5
- mistakenly opened issue
- closed HOT 1
- Issue with comparing the streams. HOT 2
- Possibly typo in test_unity_integers_64.c and test_unity_arrays.c HOT 1
- Avoid running the setup for some specific tests HOT 3
- #529 still unfixed after merge HOT 2
- PlatformIO failing to parse manifest on install.
- Game thing.com HOT 1
- How do I rename the `setUp` and `tearDown` functions? HOT 2
- Build fails with -Werror=missing-declarations when UNITY_USE_COMMAND_LINE_ARGS is enabled HOT 1
- XML/JSON based report generating? HOT 2
- Errr how u use this HOT 1
- Can you code on iPad using this app?
- I'm in secondary school first grade sooo i have no idea what I'm doing (I'm trying to tell but not expose my age) HOT 1
- Can you use this app to code on iPad?
- ssize_t asserts are missing
- Add Example for Testing using CMake
- Build fails when not using UNITY_USE_COMMAND_LINE_ARGS
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unity.