Learning to code is hard. Learning to code with tests is harder. Let's practice this art together.
People
Repo info
Activity
Kevin Lamping
@klamping
sometimes it's quicker to write a throw away test
and sometimes not worth the effort, esp. if it's a new product and the requirments are still in flux
Clint Hoagland
@vsComputer_twitter
"It depends," right? There's def gonna be cases where you want a throwaway test, nothing wrong with that.
Personal example: I write "unit tests" that use real concrete things that hit the outside world (e.g. file systems, web APIs etc) just so I know what spits out of them so that I can accurately characterize them in mocks.
I throw them out once I know how they work and the mocks are in place.
Natalie J. Bennett
@njbennett
Tests can serve different purposes:
Design aids
Documentation
Regression checking And there's at least one more that I'm not thinking of at the moment... but the point being, a test that serves #1 but doesn't help #2 or #3 much can be a great test to write and then an equally great test to delete.
Rey Winters
@reywinters03
I'm okay with throwaway tests as long as people don't depend on them. Essentially you're providing saas for people ..
Kevin Lamping
@klamping
that's the trick though. anytime you put anything useful out there, people will start depending on it :)
Clint Hoagland
@vsComputer_twitter
I really like the point Natalie made about using tests to help design your code and then realizing that it's ok to delete them if they don't provide any regression safety
Natalie J. Bennett
@njbennett
What do you mean by "depend on them?" What does it look like to depend on a test?
Kevin Lamping
@klamping
just that they're using it for validation of something
Clint Hoagland
@vsComputer_twitter
I think if a test is telling you something you still want to know, it's implicitly not a throwaway test.
In my mind a throwaway test is something you just slap together to see how something is working and after you know you don't care anymore because you assume -for whatever reason- that it isn't going to change.
Clint Hoagland
@vsComputer_twitter
(or if you don't care whether it changes I guess)
Rey Winters
@reywinters03
Story time! So there was a developer who created a demo server to show off the newly created framework. Management decided (because of a time crunch) to use this demo server as the actual server. Needless to say it couldn't support a lot of users on at the same time.
Clint Hoagland
@vsComputer_twitter
Stories of Protoduction with Rey Winters
Rey Winters
@reywinters03
That said ... Throwaway tests should be separated and not publicized or at least explicitly stated that they are not written with best practices in mind :)
Haha
Clint Hoagland
@vsComputer_twitter
OK so what I'm hearing is not that these are what I think of as "throwaway tests" but rather tests that are either bad themselves, or that test something that is itself bad(?)
Rey Winters
@reywinters03
Both...?
but that's a good point ... What does a throwaway test look like to you
I wrote a test to tell me how many directories get returned by Directory.GetDirectories if I point it at my C drive. I did this only to find out how that method works; incidentally I found out how many (98). Now I can throw that test away because it's not testing anything I care about.
Not sure of the exact minute in the presentation he said it but he described what he does about them: moves them to a folder called "crappy-tests" and then replaces them with good tests when he has time.
Rey Winters
@reywinters03
Ahhh haha yes! To me your throwaway tests are utility scripts
Kevin Lamping
@klamping
@reywinters03 that story makes me crack up, because I can totally see it happening
Rey Winters
@reywinters03
@klamping it was based on a true story ... I believe the actual upper bound limit of users were two 😂
Kevin Lamping
@klamping
haha
Rey Winters
@reywinters03
How many of you have or had created testing frameworks that ultimately were not used by the people you created it for ...?
Kevin Lamping
@klamping
:raised_hand:
was shut down after a year of development and some use
Clint Hoagland
@vsComputer_twitter
<------- this guy
Rey Winters
@reywinters03
Sigh me as well ...
Rey Winters
@reywinters03
Does anyone here go into the SUT source code and change it to be more testable?
Natalie J. Bennett
@njbennett
"Does anyone here go into the SUT source code and change it to be more testable?" All the time!
I don't like to play the "best practice" card, but it's tremendously valuable. Often a small change in the production code can eliminate giant terrible swaths of test code.
Kevin Lamping
@klamping
agreed. as a front-end dev, I don't mind an ID here and there to make testing easier
Clint Hoagland
@vsComputer_twitter
This is a theological discussion I've argued with many many devs but my position is that code that is more testable is implicitly better and if you can change code to make it more testable it will make the code better. Full stop. So you should.
Kevin Lamping
@klamping
yep
i can see purists fighting back, but I think it's overwhelmingly worth the drawbacks
Natalie J. Bennett
@njbennett
What kind of arguments do devs have against changing code for test ability?
I work in a hardcore TDD shop so that viewpoint seems utterly alien
Kevin Lamping
@klamping
well, from an html standpoint, you're adding IDs that don't serve a purpose other than for testing
in theory that clutters up the code and increase page size
but that's a pretty far stretch IMO
Clint Hoagland
@vsComputer_twitter
IME bcz it breaks their OO design and "exposes class internals," usually because I want to do shit like inject a mock
Natalie J. Bennett
@njbennett
@vsComputer_twitter ... have they heard about dependency injection?
Clint Hoagland
@vsComputer_twitter
They have and they're against it. (Those that fight me on it)