"Bart Simpson" or "Homer Simpson" is much better than "user", "123" or "test".
Why? :) They don't say anything about the test. Are these exact values important for the test to pass, or can I change them to test? I would not know because Bart Simpson doesn't have a meaning in the test context. That's my point .
I tend to use values such as irrelevant or specific-name. That way I know when a value is irrelevant for the test, or when the value is specific and required for the test to pass :)
Happy to discuss further, this topic is very interesting!
I understand. Factories can be useful but the problem I see with them is that add additional logic to your test, and forces you to keep additional context in your head when you read the test. I try to avoid helper functions unless they are very obvious.
The example you provide is clear because the test is so small, but what if the user had 15 fields instead of 2?
Here's an interesting blog post on why you should avoid keeping logic in your tests.
The example you provide is clear because the test is so small, but what if the user had 15 fields instead of 2?
It depends. If all these 15 fields are important to the test, I'll leave them as is. If not, I'll move them to some sort of helper or factory. See: thoughtbot.com/blog/the-self-conta...
Here's an interesting blog post on why you should avoid keeping logic in your tests.
Awesome post. I agree completely with it: we should always optimize tests not for code brevity but for understanding.
It depends. If all these 15 fields are important to the test, I'll leave them as is. If not, I'll move them to some sort of helper or factory.
If you have 15 fields and you want to have tests for all of them, would that not leave you with a lot of factories?
You have convinced me factories are useful, but I'm still scared of abusing them. I need to experiment more to understand the trade-offs and learn how to balance.
[..] we should always optimize tests not for code brevity but for understanding.
Could not agree more!
How to write helpful, understandable and maintainable tests are often overlooked, in my opinion, and I really enjoy learning more about it. Far too many times I've had to spend many brain cycles just to understand what a test is actually verifying.
If you have more test related blog posts to share, please send them my way, friend!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Why? :) They don't say anything about the test. Are these exact values important for the test to pass, or can I change them to
test
? I would not know becauseBart Simpson
doesn't have a meaning in the test context. That's my point .I tend to use values such as
irrelevant
orspecific-name
. That way I know when a value is irrelevant for the test, or when the value is specific and required for the test to pass :)Happy to discuss further, this topic is very interesting!
I see. I think, irrelevant data should not be at tests at all. That's why we use factories:
thoughtbot.com/blog/why-factories
Oh, I'm sorry for the confusion. I put it there because it was actually used in test:
What do you think?
I understand. Factories can be useful but the problem I see with them is that add additional logic to your test, and forces you to keep additional context in your head when you read the test. I try to avoid helper functions unless they are very obvious.
The example you provide is clear because the test is so small, but what if the user had 15 fields instead of 2?
Here's an interesting blog post on why you should avoid keeping logic in your tests.
Curious what you think!
It depends. If all these 15 fields are important to the test, I'll leave them as is. If not, I'll move them to some sort of helper or factory. See:
thoughtbot.com/blog/the-self-conta...
Awesome post. I agree completely with it: we should always optimize tests not for code brevity but for understanding.
If you have 15 fields and you want to have tests for all of them, would that not leave you with a lot of factories?
You have convinced me factories are useful, but I'm still scared of abusing them. I need to experiment more to understand the trade-offs and learn how to balance.
Could not agree more!
How to write helpful, understandable and maintainable tests are often overlooked, in my opinion, and I really enjoy learning more about it. Far too many times I've had to spend many brain cycles just to understand what a test is actually verifying.
If you have more test related blog posts to share, please send them my way, friend!