Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Unit Testing... yay or nay?

Unit Testing... yay or nay?

Scheduled Pinned Locked Moved The Lounge
testingbeta-testingquestion
78 Posts 21 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Greg UtasG Greg Utas

    I've hardly ever written a unit test. The few times I did, it was to test a complex, standalone function. Other than that, the test harness would have been far too much work. System and regression testing (automated) are where it's at. Where I worked, developers tested new features--code that they'd written, in many cases largely standalone--but almost always ran tests with their code integrated into the entire system. A decade ago, Jim Coplien (one of the original C++ gurus) wrote a good article about this. It's fairly long, so scroll to the bottom for his recommendations if you don't have enough patience. Why Most Unit Testing is Waste | PythonTest [^]

    Robust Services Core | Software Techniques for Lemmings | Articles
    The fox knows many things, but the hedgehog knows one big thing.

    J Offline
    J Offline
    Jeremy Falcon
    wrote on last edited by
    #17

    Oh and please don't turn this into one of these dumb git-sucks type debates. I'm too old for that. :sigh:

    Jeremy Falcon

    1 Reply Last reply
    0
    • J Jeremy Falcon

      Greg Utas wrote:

      Other than that, the test harness would have been far too much work

      Overlooking the "too much work" part... People that say that don't know unit testing. I can promise you that. Not sure what you define as harness, but if you mean setup, say for something data-driven, then mocking and fixtures are a thing. If anyone thinks they don't help alleviate any issues, then they don't know unit testing.

      Greg Utas wrote:

      A decade ago, Jim Coplien (one of the original C++ gurus) wrote a good article about this. It's fairly long, so scroll to the bottom for his recommendations if you don't have enough patience.

      Not trying to turn this into a debate, but you should know that titles don't mean jack to me. Don't care if they wrote an article or not or if he knows C++ or not. Doesn't mean that automatically qualifies him as the expert of all things ever created. I'm not coming at this from a n00b man; I'm just keeping it casual instead of preachy. I can tell you this man, it's usually the people that know the least about a subject that have such strong opinions. Not always, but a lot times that's true.

      Jeremy Falcon

      Greg UtasG Offline
      Greg UtasG Offline
      Greg Utas
      wrote on last edited by
      #18

      Titles also mean nothing to me. The fact that I have some respect for Coplien is therefore telling. Maybe unit tests work for you. I developed frameworks for most of my career. To test them, I developed applications that used them.

      Robust Services Core | Software Techniques for Lemmings | Articles
      The fox knows many things, but the hedgehog knows one big thing.

      <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
      <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

      N J 2 Replies Last reply
      0
      • J Jeremy Falcon

        Come to the dark side Nelek... come... (evil smiley)

        Jeremy Falcon

        N Offline
        N Offline
        Nelek
        wrote on last edited by
        #19

        Jeremy Falcon wrote:

        Come to the dark side Nelek... come... (evil smiley)

        I would, but I am too lazy and procrastinator to do it now. Maybe tomorrow?

        Jeremy Falcon wrote:

        (evil smiley)

        Something like 😈 this?

        M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

        J 1 Reply Last reply
        0
        • Greg UtasG Greg Utas

          Titles also mean nothing to me. The fact that I have some respect for Coplien is therefore telling. Maybe unit tests work for you. I developed frameworks for most of my career. To test them, I developed applications that used them.

          Robust Services Core | Software Techniques for Lemmings | Articles
          The fox knows many things, but the hedgehog knows one big thing.

          N Offline
          N Offline
          Nelek
          wrote on last edited by
          #20

          Greg Utas wrote:

          To test them, I developed applications that used them.

          That has been my approach for long too, without programming frames but Apps instead.

          M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

          1 Reply Last reply
          0
          • J Jeremy Falcon

            So I got to thinking... dangerous I know. But curious to know how many peeps unit test their code. IMO _some_ arguments can be made for not doing BDD/functional testing, but unit testing is hard to say "that's a bad thing" for. I know for me, I used to loathe the concept of unit testing. It was like just as boring and tedious as documentation (that nobody ever reads). That was right up until it saved my bacon a few times. Prior to that experience, I've only ever seen devs write crappy tests that were useless and thus considered it a feel-good exercise for a green checkmark. Didn't really think about the dev just being lousy at writing tests. Still don't do TDD though, but fo sho do unit tests after development. Anyone here big into unit testing? Yay? Nay? Has cooties?

            Jeremy Falcon

            D Offline
            D Offline
            Daniel Pfeffer
            wrote on last edited by
            #21

            IMO, it only makes sense to do unit testing when the inputs & outputs from a function/module can be specified. To take a very simple case, testing the strlen() function in C: * Input must be a non-null pointer * Output must be a non-negative integer * The (output)th character of the input is a null character. * No null characters are to be found in the range [ 0 .. (output) ) of the input In cases where the output is not easy to check (for example a trigonometric function), exhaustive testing is impractical. In this case, only very simple "sanity" tests can be performed. In real-world code I usually try to test all boundary conditions, but don't try to perform exhaustive testing.

            Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

            J H 2 Replies Last reply
            0
            • D Daniel Pfeffer

              IMO, it only makes sense to do unit testing when the inputs & outputs from a function/module can be specified. To take a very simple case, testing the strlen() function in C: * Input must be a non-null pointer * Output must be a non-negative integer * The (output)th character of the input is a null character. * No null characters are to be found in the range [ 0 .. (output) ) of the input In cases where the output is not easy to check (for example a trigonometric function), exhaustive testing is impractical. In this case, only very simple "sanity" tests can be performed. In real-world code I usually try to test all boundary conditions, but don't try to perform exhaustive testing.

              Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

              J Offline
              J Offline
              Jeremy Falcon
              wrote on last edited by
              #22

              Daniel Pfeffer wrote:

              IMO, it only makes sense to do unit testing when the inputs & outputs from a function/module can be specified.

              Fo sho, that's actually a unit test. There other type of larger tests (functional tests) that get a bit more abstract, which one can make a case for or against. But, a unit test should test a very small unit. Typically that will equate to a routine, um... unless you have 5 page long functions. :laugh:

              Daniel Pfeffer wrote:

              In cases where the output is not easy to check (for example a trigonometric function), exhaustive testing is impractical. In this case, only very simple "sanity" tests can be performed.

              Keep in mind, I don't know trig like at all... but most testing frameworks allow you to test all kinds of output. If by not being able to test trig you mean like a picture on the screen, you can even test that too whether it's against a fixture or something else. Or perhaps test the routine before it gets sent to a renderer than then also visually compare and so on. It's like riding a bike, the more you do it the mo' easy it becomes to test.

              Jeremy Falcon

              D 1 Reply Last reply
              0
              • Greg UtasG Greg Utas

                Titles also mean nothing to me. The fact that I have some respect for Coplien is therefore telling. Maybe unit tests work for you. I developed frameworks for most of my career. To test them, I developed applications that used them.

                Robust Services Core | Software Techniques for Lemmings | Articles
                The fox knows many things, but the hedgehog knows one big thing.

                J Offline
                J Offline
                Jeremy Falcon
                wrote on last edited by
                #23

                Greg Utas wrote:

                Titles also mean nothing to me. The fact that I have some respect for Coplien is therefore telling.

                Fair enough.

                Greg Utas wrote:

                Maybe unit tests work for you. I developed frameworks for most of my career

                There's absolutely no reason a framework would prevent unit testing. If you think that, and I swear I'm not trying to be mean, but you don't know unit testing. And that's ok... I don't know everything. So, just say you don't wanna do it because you don't wanna do it. :laugh:

                Jeremy Falcon

                Greg UtasG 1 Reply Last reply
                0
                • N Nelek

                  Jeremy Falcon wrote:

                  Come to the dark side Nelek... come... (evil smiley)

                  I would, but I am too lazy and procrastinator to do it now. Maybe tomorrow?

                  Jeremy Falcon wrote:

                  (evil smiley)

                  Something like 😈 this?

                  M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                  J Offline
                  J Offline
                  Jeremy Falcon
                  wrote on last edited by
                  #24

                  Nelek wrote:

                  I would, but I am too lazy and procrastinator to do it now.

                  Thanks for being honest, buddy. :laugh: :laugh: :laugh: This is why we get along.

                  Nelek wrote:

                  Something like 😈 this?

                  Yes!!!! :omg:

                  Jeremy Falcon

                  N 1 Reply Last reply
                  0
                  • J Jeremy Falcon

                    Greg Utas wrote:

                    Titles also mean nothing to me. The fact that I have some respect for Coplien is therefore telling.

                    Fair enough.

                    Greg Utas wrote:

                    Maybe unit tests work for you. I developed frameworks for most of my career

                    There's absolutely no reason a framework would prevent unit testing. If you think that, and I swear I'm not trying to be mean, but you don't know unit testing. And that's ok... I don't know everything. So, just say you don't wanna do it because you don't wanna do it. :laugh:

                    Jeremy Falcon

                    Greg UtasG Offline
                    Greg UtasG Offline
                    Greg Utas
                    wrote on last edited by
                    #25

                    Quote:

                    There's absolutely no reason a framework would prevent unit testing.

                    I wasn't talking about a framework preventing it. I was talking about testing the framework itself.

                    Robust Services Core | Software Techniques for Lemmings | Articles
                    The fox knows many things, but the hedgehog knows one big thing.

                    <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                    <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                    J 1 Reply Last reply
                    0
                    • J Jeremy Falcon

                      So I got to thinking... dangerous I know. But curious to know how many peeps unit test their code. IMO _some_ arguments can be made for not doing BDD/functional testing, but unit testing is hard to say "that's a bad thing" for. I know for me, I used to loathe the concept of unit testing. It was like just as boring and tedious as documentation (that nobody ever reads). That was right up until it saved my bacon a few times. Prior to that experience, I've only ever seen devs write crappy tests that were useless and thus considered it a feel-good exercise for a green checkmark. Didn't really think about the dev just being lousy at writing tests. Still don't do TDD though, but fo sho do unit tests after development. Anyone here big into unit testing? Yay? Nay? Has cooties?

                      Jeremy Falcon

                      R Offline
                      R Offline
                      Ravi Bhavnani
                      wrote on last edited by
                      #26

                      Yay for unit tests, because I like to sleep easy at night. :) Our DOD requires the creation/modification of unit tests when new functionality is implemented and existing functionality modified.  We don't yet do TDD but are in the process of implementing integration test projects that would make it easy for devs to write the test before writing the code. Note: IMHO best practices like these require the buy in of management.  Thankfully all our dev managers are ex-developers. /ravi

                      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                      D J 2 Replies Last reply
                      0
                      • J Jeremy Falcon

                        Daniel Pfeffer wrote:

                        IMO, it only makes sense to do unit testing when the inputs & outputs from a function/module can be specified.

                        Fo sho, that's actually a unit test. There other type of larger tests (functional tests) that get a bit more abstract, which one can make a case for or against. But, a unit test should test a very small unit. Typically that will equate to a routine, um... unless you have 5 page long functions. :laugh:

                        Daniel Pfeffer wrote:

                        In cases where the output is not easy to check (for example a trigonometric function), exhaustive testing is impractical. In this case, only very simple "sanity" tests can be performed.

                        Keep in mind, I don't know trig like at all... but most testing frameworks allow you to test all kinds of output. If by not being able to test trig you mean like a picture on the screen, you can even test that too whether it's against a fixture or something else. Or perhaps test the routine before it gets sent to a renderer than then also visually compare and so on. It's like riding a bike, the more you do it the mo' easy it becomes to test.

                        Jeremy Falcon

                        D Offline
                        D Offline
                        Daniel Pfeffer
                        wrote on last edited by
                        #27

                        One can only test a trigonometric function by comparing its results to the results of another implementation coded using a different approximation. The problem is that one has to write this additional implementation, at least doubling the work that must be performed. One can perform spot checks by comparing the results to known result calculated by another implementation, but that is hardly an exhaustive test of one's implementation.

                        Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                        J 1 Reply Last reply
                        0
                        • R Ravi Bhavnani

                          Yay for unit tests, because I like to sleep easy at night. :) Our DOD requires the creation/modification of unit tests when new functionality is implemented and existing functionality modified.  We don't yet do TDD but are in the process of implementing integration test projects that would make it easy for devs to write the test before writing the code. Note: IMHO best practices like these require the buy in of management.  Thankfully all our dev managers are ex-developers. /ravi

                          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                          D Offline
                          D Offline
                          Daniel Pfeffer
                          wrote on last edited by
                          #28

                          Ravi Bhavnani wrote:

                          Note: IMHO best practices like these require the buy in of management.  Thankfully all our dev managers are ex-developers.

                          Upvoted for this. Over the decades, I have tried many times to get better practices to be adopted in my places of employment. My attempts have failed, usually when the managers realized that it isn't a magic bullet, and that there is a learning curve for adoption.

                          Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                          J 1 Reply Last reply
                          0
                          • J Jeremy Falcon

                            So I got to thinking... dangerous I know. But curious to know how many peeps unit test their code. IMO _some_ arguments can be made for not doing BDD/functional testing, but unit testing is hard to say "that's a bad thing" for. I know for me, I used to loathe the concept of unit testing. It was like just as boring and tedious as documentation (that nobody ever reads). That was right up until it saved my bacon a few times. Prior to that experience, I've only ever seen devs write crappy tests that were useless and thus considered it a feel-good exercise for a green checkmark. Didn't really think about the dev just being lousy at writing tests. Still don't do TDD though, but fo sho do unit tests after development. Anyone here big into unit testing? Yay? Nay? Has cooties?

                            Jeremy Falcon

                            L Offline
                            L Offline
                            lmoelleb
                            wrote on last edited by
                            #29

                            Sometimes I am lazy and skip them - typically when I am not quite sure I have the main "flow" worked out. It gives a short term benefit not spending time on them, but of course that has to be paid later - so I do at least make sure to write decoupled code that I can easily add the test. If I am reasonable certain of the flow, I write the test along with the code (sometimes even before as TDD, but that is rare). It is often much faster to itterate over a code block in the test than running an application. And of course, when I do go back and write the tests I skipped I find a bug or two.... In general it works as an investment: loose an hour writing a test now, or waste a day at a later time due to lack of tests... Sometimes the hour now is worth more than the day in the future. It only becomes a problem if the cost of the day in the future isn't even considered when skipping the test.

                            J 1 Reply Last reply
                            0
                            • R RickZeeland

                              Nay, we tried it for a while, but our code is changing so rapidly that maintaining the unit tests proved to be a daunting task for our small team of developers. But it might be fine if you have enough developers to maintain the tests and your code base is not changing too rapidly.

                              L Offline
                              L Offline
                              lmoelleb
                              wrote on last edited by
                              #30

                              Funny how experience can be different. For me, unit tests speed up changing code.

                              R J 2 Replies Last reply
                              0
                              • L lmoelleb

                                Sometimes I am lazy and skip them - typically when I am not quite sure I have the main "flow" worked out. It gives a short term benefit not spending time on them, but of course that has to be paid later - so I do at least make sure to write decoupled code that I can easily add the test. If I am reasonable certain of the flow, I write the test along with the code (sometimes even before as TDD, but that is rare). It is often much faster to itterate over a code block in the test than running an application. And of course, when I do go back and write the tests I skipped I find a bug or two.... In general it works as an investment: loose an hour writing a test now, or waste a day at a later time due to lack of tests... Sometimes the hour now is worth more than the day in the future. It only becomes a problem if the cost of the day in the future isn't even considered when skipping the test.

                                J Offline
                                J Offline
                                Jeremy Falcon
                                wrote on last edited by
                                #31

                                Same man. Not every piece of code is tested, but for the code I know that has to work correctly or else... it is.

                                Jeremy Falcon

                                1 Reply Last reply
                                0
                                • Greg UtasG Greg Utas

                                  Quote:

                                  There's absolutely no reason a framework would prevent unit testing.

                                  I wasn't talking about a framework preventing it. I was talking about testing the framework itself.

                                  Robust Services Core | Software Techniques for Lemmings | Articles
                                  The fox knows many things, but the hedgehog knows one big thing.

                                  J Offline
                                  J Offline
                                  Jeremy Falcon
                                  wrote on last edited by
                                  #32

                                  Greg Utas wrote:

                                  I wasn't talking about a framework preventing it. I was talking about testing the framework itself.

                                  I know. Try again. I also know it's clear this conversation isn't gonna go anywhere. You can't say "bruh I don't know it and I don't wanna use it just because". Which means, we're just wasting time here.

                                  Jeremy Falcon

                                  Greg UtasG 1 Reply Last reply
                                  0
                                  • D Daniel Pfeffer

                                    One can only test a trigonometric function by comparing its results to the results of another implementation coded using a different approximation. The problem is that one has to write this additional implementation, at least doubling the work that must be performed. One can perform spot checks by comparing the results to known result calculated by another implementation, but that is hardly an exhaustive test of one's implementation.

                                    Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                                    J Offline
                                    J Offline
                                    Jeremy Falcon
                                    wrote on last edited by
                                    #33

                                    Daniel Pfeffer wrote:

                                    One can only test a trigonometric function by comparing its results to the results of another implementation coded using a different approximation.

                                    There's nothing preventing you from unit testing that. It's call mocking and just about every testing framework supports that. Testing approximations with even random values is completely doable in just about any testing framework.

                                    Daniel Pfeffer wrote:

                                    One can perform spot checks by comparing the results to known result calculated by another implementation, but that is hardly an exhaustive test of one's implementation.

                                    There's always more code to write a unit test even if you're testing how to cross the street with grandma. That's not the point. The point is, it's worth it. And tests are an art just like software development, it's as exhaustive as you make it. Just because I don't know trig, doesn't mean I don't know things like cryptography and randomness. You can test that. Promise. But, let's pretend you can't test that one tiny part. Just for the sake of argument. You can still test 80-90% of the rest of the application. Edit: Btw, I hope this post didn't come across as sour man. I never know these days, and well most online chats are... you know. :~

                                    Jeremy Falcon

                                    D 1 Reply Last reply
                                    0
                                    • R Ravi Bhavnani

                                      Yay for unit tests, because I like to sleep easy at night. :) Our DOD requires the creation/modification of unit tests when new functionality is implemented and existing functionality modified.  We don't yet do TDD but are in the process of implementing integration test projects that would make it easy for devs to write the test before writing the code. Note: IMHO best practices like these require the buy in of management.  Thankfully all our dev managers are ex-developers. /ravi

                                      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                                      J Offline
                                      J Offline
                                      Jeremy Falcon
                                      wrote on last edited by
                                      #34

                                      Ravi Bhavnani wrote:

                                      Yay for unit tests, because I like to sleep easy at night. :)

                                      Preach brother.

                                      Ravi Bhavnani wrote:

                                      Our DOD requires the creation/modification of unit tests when new functionality is implemented and existing functionality modified.

                                      What's DOD mean? I think Dept of Defense when I hear that. Just curious.

                                      Ravi Bhavnani wrote:

                                      We don't yet do TDD but are in the process of implementing integration test projects that would make it easy for devs to write the test before writing the code.

                                      Be curious to know how it goes. I've never done full blown TDD (I'm stubborn), but would love to hear a use case about it.

                                      Ravi Bhavnani wrote:

                                      Thankfully all our dev managers are ex-developers.

                                      The best ones are, buddy. :thumbsup:

                                      Jeremy Falcon

                                      R D 2 Replies Last reply
                                      0
                                      • D Daniel Pfeffer

                                        Ravi Bhavnani wrote:

                                        Note: IMHO best practices like these require the buy in of management.  Thankfully all our dev managers are ex-developers.

                                        Upvoted for this. Over the decades, I have tried many times to get better practices to be adopted in my places of employment. My attempts have failed, usually when the managers realized that it isn't a magic bullet, and that there is a learning curve for adoption.

                                        Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

                                        J Offline
                                        J Offline
                                        Jeremy Falcon
                                        wrote on last edited by
                                        #35

                                        And I upvoted your upvote... because why not. :laugh:

                                        Jeremy Falcon

                                        1 Reply Last reply
                                        0
                                        • J Jeremy Falcon

                                          Greg Utas wrote:

                                          I wasn't talking about a framework preventing it. I was talking about testing the framework itself.

                                          I know. Try again. I also know it's clear this conversation isn't gonna go anywhere. You can't say "bruh I don't know it and I don't wanna use it just because". Which means, we're just wasting time here.

                                          Jeremy Falcon

                                          Greg UtasG Offline
                                          Greg UtasG Offline
                                          Greg Utas
                                          wrote on last edited by
                                          #36

                                          If you develop a framework, you need to eat your own dog food. A cliche, I know. But building an application to test it uncovers not only bugs, but things that should be added or reworked to make developers' lives easier. We're undoubtedly wasting time here. You're not interested in any contrary opinions but just want to virtue signal.

                                          Robust Services Core | Software Techniques for Lemmings | Articles
                                          The fox knows many things, but the hedgehog knows one big thing.

                                          <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                                          <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                                          J 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups