Unit Tests

Amazon / Eng
tUSh53

Amazon Eng

PRE
Wink
tUSh53more
Jun 14, 2018 45 Comments

I’m an SDE II with 9 yoe / TC 250K and have spent my whole career doing iOS and Android development. I had never written a single unit test / integration test / UI test until about a year ago when I joined Amazon because the build automatically breaks if code coverage drops for any change.

I’ve always relied on manual testing for all apps I’ve written, and I feel like it has worked out fairly well because I’ve been able to create some very high quality apps.

I am struggling with imposters syndrome because every other developer seems to write unit tests without thinking twice about it. For me, I only write them to keep the pipeline from breaking. It takes me twice as long to write the tests as it does to write the code, and feels like a total waste of time. I’ve never actually had a test “save me” from introducing a bug. Often my changes will break existing tests, but not because I broke anything, so I just end up having to refactor the test.

Does anyone else feel this way?

comments

Want to comment? LOG IN or SIGN UP
TOP 45 Comments
  • Google wholly
    No unit test, no respect from me.
    Jun 14, 2018 1
  • Amazon idhe72
    Sde2 with 250k tc who doesn’t believe in unit tests and automated testing 🙄 🤦🏻‍♂️

    fuck this shit.
    Jun 14, 2018 0
  • Uber rfPB87
    It’s not just about what you make - what if someone else modifies your code later and breaks it and there’s no test to catch it? When there are a lot of people touching a code base, unit testing is extremely important
    Jun 14, 2018 2
    • Uber Intern18
      This guy || gal fucks!
      Jun 14, 2018
    • Amazon Hamdrew
      Hard and gay and proud
      Jun 17, 2018
  • Microsoft jack911
    You’ll get better at it with time.
    Jun 14, 2018 5
    • Amazon / Eng
      tUSh53

      Amazon Eng

      PRE
      Wink
      tUSh53more
      OP
      I think I will get better at actually writing them more quickly with a little more practice.

      The bigger problem is I have yet to see the value of them. How many times have unit tests helped you prevented a bug from being introduced? So far, zero times for me.
      Jun 14, 2018
    • Amazon / Eng hHMa46
      You don't understand half the point of unit tests then. If someone else modifies the code later and introduces an unexpected behavior, your unit test will catch it.
      Jun 14, 2018
    • Amazon / Eng
      tUSh53

      Amazon Eng

      PRE
      Wink
      tUSh53more
      OP
      I am aware of these points conceptually, but for some reason, these scenarios haven’t really ever happened to me.

      I have had to refactor other developer code that did have unit tests. The unit tests broke because I changed functionality, but that was my intention, so I just had to refactor the unit test as well. Just seemed like they got in the way and didn’t help me in any way.

      I would like to learn to appreciate and understand the value of testing. So any resources/books you can point me to would be appreciated. Or any examples you can share of when the dev effort to write tests was less than the time you would have spent dealing with problems that could have been solved by having tests in the first place.
      Jun 14, 2018
    • Amazon aladin
      tUSh53@ unit test is to help developer. If you are thinking they are just a blocker in developement then you need to think about the piece of code you testing is worth testing. I write unit test to help not intorduce regression bug. You may not see the real value right away if your code works the way it should but other developer working on that same piece of code might not be as good as you and may introduce bug. Now your peer will blame you for not adding the unit test because you never wrote one.
      Jun 16, 2018
    • Amazon aladin
      Ideally we should not write a code that cant be tested unless in few scenarios. I think more than a book you need to talk to someone NOT from your team to discuss the value of unit testing. I have helped the team writing test and saving from potential bugs. I dont write bug free code all the time and unit test always comes handy. Why would developers in other companies not push for unit test?
      Jun 16, 2018
  • Google hdifhdusb
    I've seen unit/integration tests prevent million dollar catastrophies, and I've seen the lack thereof result in them.

    Take a look at the book "working effectively with legacy code", which defines legacy code as code that is not covered by tests. It might hit home a little.
    Jun 14, 2018 3
    • Amazon / Eng
      tUSh53

      Amazon Eng

      PRE
      Wink
      tUSh53more
      OP
      Thanks for the book reference, I will definitely check it out. Any other resources I can use to further appreciate the value of unit tests would be great as well.
      Jun 14, 2018
    • Amazon / Eng
      tUSh53

      Amazon Eng

      PRE
      Wink
      tUSh53more
      OP
      Can you describe any examples of when unit tests have prevented catastrophies as you said?
      Jun 14, 2018
    • Google hdifhdusb
      It was at Amazon, actually. :)

      I can't give too much detail, but think about the cost to the company if some fulfillment system does something that makes each shipment a few pennies more expensive. Maybe some cost calculation is off due to a rounding error, and it causes some inefficient inventory assignments to customer orders. At scale, that kind of minor thing is not trivial, but can be incredibly hard to just spot in a code review.
      Jun 14, 2018
  • Starbucks / Eng Code9000
    It’s usually a code smell if it’s overly hard to write a unit test for something. I’ve always noticed there seems to be less emphasis with unit tests on iOS projects.

    Either way getting good at unit tests takes practice. Following the SOLID (Clean code acronym) development principles will make your life easier.
    Jun 14, 2018 0
  • Microsoft wzNU83
    When I got to my current team they didn't gate check-ins on unit tests. Every deployment was a fucking nightmare. We rolled back constantly. I could never guarantee to another team when our changes would be released. So I led by example and started writing tests for every new change, even for code I didn't originally write.

    Now we can make huge swathing changes with confidence because we know the service is behaving as expected. It's a night and day difference.

    I'm a practical person. If you are writing a simple app with a small team, then sure you might not benefit from test cases. However if you're dealing with 15 features, where each feature has 20+ different scenarios, you will want those tests. They will vastly improve your development velocity and software quality.
    Jun 14, 2018 0
  • What is there even to struggle with? Just use assertEquals everywhere and @Test(expected=whateverException) occasionally
    Jun 14, 2018 3
    • Uber rfPB87
      There are some nontrivial situations for sure. Creating mocks, asynch processes like network calls, etc
      Jun 14, 2018
    • Google / Eng
      barkybark

      Google Eng

      PRE
      Microsoft
      barkybarkmore
      ExpectedException better than nothing but still no bueno, it passes the test case when anything in the test throws the exception you want, even scaffolding/setup/etc. Truth.assertThrows has finer granularity
      Jun 14, 2018
    • Wayfair / Eng
      hErg55

      Wayfair Eng

      PRE
      Cognizant
      BIO
      Software Engineer 2
      hErg55more
      Also realize, that unit testing has challenges when you depend on some code which is static or private and cannot be mocked, so you have to remove those dependencies and then test. This is often seen with legacy code. You may not be able to mock existing apis unless you are sure they are written in a right way. You fall in this trap if you you don't follow TDD.
      Mar 5
  • Microsoft ssss
    Manual testing does not catch regressions.

    Writing effective tests is a skill that you develop, just like you've improved your coding abilities over the years. It gets easier over time.
    Jun 14, 2018 0
  • Microsoft melv
    Yikes
    Jun 14, 2018 0
  • Credit Karma / Eng bertrussel
    There is no way you've been writing code for 9 years if you're asking a question like this
    Jun 14, 2018 2
    • Amazon / Eng
      tUSh53

      Amazon Eng

      PRE
      Wink
      tUSh53more
      OP
      I have. The first 8 years were at smaller startup companies (between 5-100 people). I’m guessing this may be why I’m lacking the understanding of the importance of unit tests because startups either fail or pivot to something totally new before the code has a reason to be rewritten or refactored by someone else.
      Jun 15, 2018
    • Amazon / Eng IL2 2/F
      It is possible, a lot of legacy code is like that.
      Jun 16, 2018
  • LinkedIn / Eng Umgak
    Take a longer-term view. The tests are not necessarily there to stop YOU from breaking things, but to stop future interns from breaking what you made :)
    Jun 14, 2018 0
  • Two Sigma blitty
    > I’ve never actually had a test “save me” from introducing a bug.

    It's not to save you, it's to stop future engineers from breaking your shit.
    Jun 14, 2018 1
    • Amazon / Eng
      tUSh53

      Amazon Eng

      PRE
      Wink
      tUSh53more
      OP
      I understand the principle, but I have been that “future engineer” a few times now, and the tests that others wrote before me haven’t prevented me from breaking anything.
      Jun 15, 2018
  • Google yue
    Doesn't iOS and Android code have unit tests?
    Jun 14, 2018 1
    • Amazon / Eng
      tUSh53

      Amazon Eng

      PRE
      Wink
      tUSh53more
      OP
      Yes, absolutely. I believe the testing tools and methodologies are more mature on web and backend development though.
      Jun 14, 2018
  • New / Eng
    heGc11

    New Eng

    PRE
    AngelList
    heGc11more
    How the fuck do you refactor code confidently without tests? Manual testing can only go so far. Wastes a lot of time when pm/qa/user catches the bug in the production.
    Jun 16, 2018 0
  • Microsoft btIE17
    You should look at unit tests not just as a way to prevent bugs rather as a way to prevent future regression and as a POC.
    Jun 15, 2018 0
  • Wells Fargo / Eng kiwiBird8
    Much of the time a unit and a class should be same thing
    Jun 15, 2018 3
    • Amazon eigh5689
      That's when we see people testing getters, setters and builders, instead of putting the effort to write integration tests
      Jun 15, 2018
    • Wells Fargo / Eng kiwiBird8
      I have never seen someone test data beans.
      Jun 15, 2018
    • Amazon eigh5689
      That's awesome. I worked in an org which mostly had poor unit tests and hardly any integ tests. Nobody knew what would break if a certain code change is introduced. People try to meet a certain code cov value and write crappy unit tests in a hurry to ship code. Hardly anyone reviewed unit tests
      Jun 15, 2018
  • Wells Fargo / Eng kiwiBird8
    Integration tests tie those together
    Jun 15, 2018 1
    • Amazon aladin
      Integration and unit tests serve different purposes. Are you saying one can write integration test in place of unit test?
      Jun 16, 2018
  • Wells Fargo / Eng kiwiBird8
    And I agree with others that poorly written units (which are the majority) are "check the box". They look good on a report but don't mean much. Well written u it tests fo help but take about as much consideration as the code they are testing once you factor in all test cases
    Jun 16, 2018 0
  • Wells Fargo / Eng kiwiBird8
    Depends on definition. Some would say a unit is a class so integration or functional tests are those that tie together a logical construct such as the creation, invocation, and response of a back end system. Some would say integration is putting your component with others such as your web service with other web services in a front end
    Jun 16, 2018 0

Salary
Comparison

    Real time salary information from verified employees