-
Notifications
You must be signed in to change notification settings - Fork 61
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
Suggested test guidelines #18
base: main
Are you sure you want to change the base?
Conversation
Over all pretty solid :) Some thoughts to add to the discussion: Do we favor comments over explicitly putting the This example: What about the word Example: What do you think? |
Some other things we could think about adding: Encourage the usage of test builders to construct the objects we want to test. I have started using these for the tests I'm making for the code generator currently. Avoid mocking as much as possible and push side effects as far up the stack as possible. As this makes the tests much less brittle and independent from the implementation. Test file structure, where do we put the test files and what names do we give them? For example in the case of the analyzer I have many test files for a single method as the tests are several thousands lines of code. Do we want some guideline for how to organize our files? Test scope, how much code are we testing? Personally I think unit tests that cover large amount of (pure) code is to be preferred, meaning potentially multiple classes are tested indirectly. Perhaps what @SandPod would call module tests. Unit tests that only test a single method deep inside the logic are in my experience pretty useless and gets in the way. There are of course exceptions such as smaller methods that are used in many different places or are critical, I wouldn't mind a test that explicitly verifies a regex for example. Abstraction level of tests. I think encouraging a direct and explicit test code is in most cases a benefit. I.E. not hiding expects deep in some hidden method or obscure test setups. As a developer you should be able to more or less understand the test by only looking at a specific test in isolation. Thoughts? :) |
Good thought! I don't think it is so important that we assert a specific phrasing, if some other word better communicates the expected outcome so that it is helpful for the future developer that reads it, then that should be fine to use. What I think is most important is that the pattern is there so that readers don't have to adjust the way they read the description. And more importantly don't have the parts either switching position or missing. In the example with the Cat (even if that is probably not the best example) I think the parts are still clearly communicated. But might still be good to update the examples so that they all use the same formatting, even if we don't want to lock down the phrasing. |
I think all of these with the exception of the last one are worth adding and with the following comment. Test scope -I think this boils down to how many people are modifying the code at a given time. If we are few people with good knowledge, Abstraction level of tests For the last one I definitely think that expects should be clear, but I wouldn't mind allowing tests to have their own helper expect method when working with either complex objects or asserting large states. I believe this is very situational and locking it down could creates bad code patterns with a lot of repetition, that then needs to be parsed by the future test reader. |
Suggestion for test guidelines.
There doesn't seem to be any general test guidelines for dart provided by google. So I created this based on common best practices and applied them to the dart test framework.
Does this seem reasonable?
Anything missing?