News for hackers. Stuff that matters.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by zebraflask on Sunday November 26, 2017 @04:44PM (#15783194)
Unit testing tells you what you already know. It's kind of pointless, when you think about it (unpopular opinion). If you have a handle on your code there's rarely any need for it.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by sinhpham on Sunday November 26, 2017 @05:28PM (#15783439)
No. Software evolve and there's value in knowing your assumptions still hold after the change/refactor.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by astrange on Sunday November 26, 2017 @08:06PM (#15784070)
A unit test is the worst way to capture that, because you've removed all the parts that evolve.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by psyc on Sunday November 26, 2017 @10:48PM (#15784659)
To echo the original comment, I already know half my assumptions don't hold anymore, and I don't care about them. Unit tests are just more code to maintain. It's like vastly expanding the requirements, unnecessarily.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by zebraflask on Sunday November 26, 2017 @05:48PM (#15783533)
I don't understand that but thank you for your opinion.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by spc476 on Sunday November 26, 2017 @07:19PM (#15783891)
I've been using a program I wrote for 18 years now. The code today is not the same as the code 18 years back. I have slowly modified the code as ideas for new features come up, old features removed because they aren't used anymore, and foundational code rewritten as I found better implementations (or the previous implementation was a mistake [1][2]. Making a sweeping change (like re-implementing some core code) is dangerous because of the threat of new bugs, which is why tests are important (although I tent to prefer integration tests over unit tests).

[1] I used to have an error logging mechanism in place that would record where in the code the error happened (in addition to other information) and how it propagated up through the code.

While it wasn't that hard to use, per se, it was bothersome when I had to add an error (each error had a unique ID and because of language issues and tooling, that was a manual process). And it really never paid back its implementation cost in terms of reporting, so I finally ripped it out.

[2] I had my own version of C's FILE* [3] that ended up being a horrible abstraction---it was so confusing that I could never remember how to use it, and I wrote the code. I got fed up with it, and ripped that out, replacing it with native IO calls.

[3] For stupid reasons now that I think back on it.

Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by kovacs on Sunday November 26, 2017 @08:27PM (#15784156)
The simple way to say it is that once your code gets too complicated to keep all the execution paths in your head (sooner than you think), tests are what enable you to make sure you didn't forget an assumption you made about how it should work.

Do you like going back to manually verify things still worked after you make a foundational change? Or do you just trust yourself to know you've not impacted anything negatively? Do you honestly believe that's good use of your brain power even if true? Do you enjoy being married to that code? Because that's exactly what happens as nobody but you can work on it. That strategy works out well for employees to become key men and get big retention bonuses so there is some merit to your approach :-)

Not to mention the team impact to cowboy coding. It's a selfish approach to software development and is often undertaken by bully developers that say things like "use the source" as a way to make you feel dumb for not wanting to spend all day trying to untangle their likely insane code. All because they were too lazy to use a little empathy and be a good teammate.

To recap: Tests document and improve your design, verify functionality, provide leverage to accelerate development, and reduce "bus factor" risk. I don't care what a small sample data set says to the contrary there's really little debate that when wielded properly these tools and techniques do improve software on multiple dimensions that go beyond the software itself and heavily impact the business.

20+ years of product development experience in lots of teams/products inform this opinion. Let's see the data on how your business grinds to a halt when these tools aren't used and the code base gets increasingly larger and complex and people leave. Tell me about how you don't need those automated tests as you approach technical debt bankruptcy and all your key people have left. "Use the source" is a terrible response to that problem.

Rewrites can be fun though so maybe that's the answer. It sure worked out well for Netscape. ;-)

Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by valuearb on Sunday November 26, 2017 @09:37PM (#15784428)
Unit tests are a poor way to validate code behavior. 30+ years of development has taught me that validation tests within the code itself are far better.

1) They run whenever the product runs. Good logging code tells you when it fails, even on customers devices.

2) By being part of the production code, they are far easier to keep up to date as the code changes even through refactoring.

3) They don’t force you to change anything about how you code.

Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by jacob019 on Monday November 27, 2017 @11:28AM (#15788503)
Agreed. I like to test the validity of a function's input and throw an exception if it fails. It catches most regressions with a nice error message.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by mastox on Sunday November 26, 2017 @10:54PM (#15784689)
Not sure I understand. Can you give an example?
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by psyc on Sunday November 26, 2017 @10:51PM (#15784675)
Why not just say that unit tests are a management methodology for mixed-skill teams? There's no need to invoke 'bully devs' just because inexperienced or un-conscientious developers exist.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by aurelianito on Sunday November 26, 2017 @08:36PM (#15784191)
Being proud of your lack of understanding is quite sad.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by jacob019 on Sunday November 26, 2017 @07:03PM (#15783823)
Usually I feel like the only person who doesn't unit test. I've heard all of the arguments and I like the theory, but practically I don't want to spend the time on it, and I maintain a large codebase. Regressions are easily spotted and corrected in a well structured code base. Could occational bugs be spotted before production with unit tests? Sure! But it isn't worth the time in my case.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by valuearb on Sunday November 26, 2017 @09:48PM (#15784471)
I’ve tried to write unit tests. They just haven’t been worth the effort.

1) It takes more time.

2) In any complex application, unit testing requires creating mocks to separate the code you are testing from live subsystems.

3) That requires modifying your production code to be easily mockable in ways that don’t benefit the production code base.

4) Unit tests are by default artificial. They don’t test real world usage.

5) As you refactor production code, you have to rewrite unit tests, adding more overhead.

A far better way to write tests is within your production code. Validate every parameter and every assumption. Raise errors when possible, log everything else.

This is far easier to develop, and maintain. It runs when you testers, and customers use the applications.

Now I write desktop and mobile apps. If I wrote APIs and servers unit tests would become far more useful. But on device most of my problems can only be caught by integration tests, not unit tests.

Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by zo7 on Sunday November 26, 2017 @11:17PM (#15784791)
> A far better way to write tests is within your production code. Validate every parameter and every assumption. Raise errors when possible, log everything else.

> It runs when you testers, and customers use the applications.

Do you rely on any sort of automated testing to catch errors before it gets to your customers? From a business standpoint it doesn't feel right to offload testing to your users, especially in more critical systems.

Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by valuearb on Thursday November 30, 2017 @10:14AM (#15816330)
Our testing is by hand, we have a QA lead and entire team helps.

Verification isn’t offloading testing, it’s monotoring real world usage to find out where it differs from testing. The hard part is the logs can be a torrent of data, you need to have a process to monitor and escalate.

i’d like to automate testing. But it has to be no more work than manual testing, and/or it has to be as effective or better than manual testing. And i can’t see either of those being true.

Most of my bugs can’t be caught by unit tests. For example one common category is where previous devs made assumptions where code normally works fine, but fails in specific edge cases from multiple thread timing or view controllers being disposed. i don’t know how to automate those tests.

Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by psyc on Sunday November 26, 2017 @10:45PM (#15784651)
You're not the only one, but it can be an unpopular opinion. Of course we wrote very large code bases with no unit tests for decades, before it became a blessed cult of sorts. I know when I've written a method that's so inherently tricky, that I need a unit test for peace of mind. It's rare, and I prefer not to write tricky methods, or complicated architectures. This is practically impossible to avoid on a large team of mixed skill and weak leadership. I prefer not to work on teams like that.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by capitalsigma on Sunday November 26, 2017 @08:26PM (#15784153)
How do you catch a regression without tests? Do you wait until it launches and crashes in production?
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by jacob019 on Sunday November 26, 2017 @08:48PM (#15784247)
No unit tests. With good code structure regressions are minimal, most are caught with practical testing. Ocationally one slips through to production, is reported, and quickly patched. It's rare and something that I'm sure happens to everyone, even with unit tests. I don't tell people to do it my way, but it works for me and my company.
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by capitalsigma on Sunday November 26, 2017 @08:50PM (#15784255)
What is a "practical test"?
Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by jacob019 on Sunday November 26, 2017 @08:59PM (#15784287)
I just mean a manual test of application functionality. Maybe some manual function calls. Nothing automated or saved.

BTW, the code is an ecommerce platform, not just a website but dozens of integrated applications that handle everything from product selection to order fulfillment, and everything inbetween. 11 years of code that dozens of people use daily to process hundreds of thousands of orders per year.

Re:Unit Testing Doesn’t Affect Codebases the Way You Would T... by andrewmcwatters on Monday November 27, 2017 @10:59AM (#15788299)
Practically speaking, new employees, and fast rotating contractors don't know shit about what your code is _supposed_ to be doing.

As you scale codebases and teams, it becomes necessary. With small single-developer projects, it's not.