[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
What do you need unit tests for, anon? Why don't you just
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 16
Thread images: 2
File: 1436372984706.gif (2 MB, 480x292) Image search: [Google]
1436372984706.gif
2 MB, 480x292
What do you need unit tests for, anon? Why don't you just to it right the first time?
>>
>>55561776
>do it right the first time
I'm sure that's possible

But anyway, unit tests are important because units are typically large. And you typically test that they work with other layers that are mocked out
>>
>>55561776
>Why don't you just to it right the first time?
because theres always a second and third time but the code still has to pass all tests the first version did.
>>
lol why even write code to do any task? why not just do the task yourself? :/
>>
File: 1444990062224.png (152 KB, 359x414) Image search: [Google]
1444990062224.png
152 KB, 359x414
>that guy who spends more time writing unit tests than he does writing code
>and he's not even working in enterprise
>>
>>55561812
>>55561968
>>55562050
unthinking wageslave drones

>>55562838
actual programmer
>>
>>55561776
Unit tests aren't for proving to *you* that you're "right". Unit tests are for proving to a guy that will work on a completely different part of the codebase 2 years down the road, that his modifications don't have unexpected effects in the part written by you.
>>
i can see some theoretical value in unit testing. i personally don't use it yet.
there's just so many things that are difficult to test, and too many things the tests won't catch.

for example i'm writing a program that makes changes to the file system at a scheduled time. How do I test that? Do I make the file system changes and then revert them? What if I'm making changes to a database? Do I have a dummy database that is constantly updating from the production database?
>>
>>55563525
>program that makes changes to the file system at a scheduled time. How do I test that?

fake out the file system part.

>Do I make the file system changes and then revert them?

no you fake it out.

>What if I'm making changes to a database? Do I have a dummy database that is constantly updating from the production database?

you can use dummy db or you can just fake out that layer too.

inb4 wah! wah! but thats not testing everything!
you're right it aint but 80% is waaaaaaaaaaaaaaay better than none.

unit tests...

1/ test the code
2/ document the code
3/ are a force for good design on the code
4/ protect you from changes elsewhere in the system
>>
>>55563525
This is why you have a testing environment. Or do you just go straight from Dev to Prod?
>>
>>55565106
what if i have a 15 line method, the part that modifies the file system or db is in there? do I add an if debug statement that only runs it if its not in debugging mode?
>>55565146
what do you use for a test environment?
>>
>>55565320
junit, ctest, list goes on
>>
>>55565320
>if debug statement that only runs it if its not in debugging mode?

thats one way.

there are others, picking which way to do it depends on your particular context.

in an oo context you might rip off the interface to your FileSystem class called say FSInterface them implement a fake one inheriting from that interface.
>>
>>55563459
basically this.

If any of you NEET fucks have ever worked on an enterprise level project you should understand.
>>
>>55561776
manual testing costs a lot of time. Unit tests bring that down, serve as documentation and guarantee system behavior is correct, not only on normal conditions but also on out of range and unexpected inputs.

Also seeing dots turn green is entertaining.
>>
>>55561776
He's starting to look like the amazing atheist.
Thread replies: 16
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.