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. It's OK Not to Write Unit Tests

It's OK Not to Write Unit Tests

Scheduled Pinned Locked Moved The Lounge
csharpc++comtestingbeta-testing
46 Posts 24 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.
  • C CPallini

    Wow, I thought unit testing was all about focusing on the functionality of a quite logical independent unit, "not (a) test (that) cannot talk to a database, communicate across the network, touch the filesystem, run concurrently with another test, or require extensive setup. If they are any dependencies, they are mocked away". Dogmatic approaches are pretty useless for me. :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    K Offline
    K Offline
    Kenneth Kasajian
    wrote on last edited by
    #34

    I think you're missing the point. A unit test ultimately tries to validate the functionality of a single piece of code. Imagine a method being a math function. You simply want to validate that *that* code is correct, not the rest of the system. So you do that by mocking everything around it. It's a bad argument to say that by doing a unit test it doesn't test how the code works integrated with the rest of the system, therefore a unit test is not useful. No one is saying that the unit test is the only test for code. In fact, some argue that's not even a "test", but a way to verify the the design. You still need integration, functional, exploratory tests, etc.

    ken@kasajian.com / www.kasajian.com

    C 1 Reply Last reply
    0
    • M Member 96

      Unit tests like so much methodology these days are simply ways to commoditize software development. Nothing more, nothing less and like cows to slaughter most developers eat up these kinds of methodologies like candy all the while ignoring the fact that these were designed primarily to make us replaceable worthless cogs in a big machine of corporate development. Unit tests are on most levels counterproductive and worthless to any decent software developer who can recognize bad code before or while they are writing it and nip it in the bud. They're great for accounting and managerial types though so .... yay for them! :) Software developers used to be gods in their domain, now they're just easily replaced cogs in a giant machine of mediocrity and have no one to blame but themselves when their work can be easily outsourced or indeed they themselves can be easily replaced with someone cheaper and less experienced.


      "Creating your own blog is about as easy as creating your own urine, and you're about as likely to find someone else interested in it." -- Lore Sjöberg

      K Offline
      K Offline
      Kenneth Kasajian
      wrote on last edited by
      #35

      You're right. Unit testing makes it easier to replace developers. Is that a bad things? So are you saying you won't write unit tests so that you're not as easily replaceable? The more you're difficult to replace, the more you're like to be stuck at the same job.

      ken@kasajian.com / www.kasajian.com

      M 1 Reply Last reply
      0
      • M Mateusz Jakub

        I don't understand article, or author is writing about writing unit test to his own code? If yes then, something like this is like leaving thief to judge himself. When you write app alone unit tests are pointless. "Let's be honest. Your tests mostly follow the “happy path”." Get a tester and You won't follow the "happy path" in tests.

        K Offline
        K Offline
        Kenneth Kasajian
        wrote on last edited by
        #36

        You're absolutely right. A unit test can only verify the programmer's assumptions, which is why it's never going to be enough, and you need a separate person to run the functional and exploratory tests. Don't downplay unit-testing because of this fact. No one is saying unit tests are the only tests. You're using a staw-man argument. If you write the code perfectly the first time, without unit tests, you still need unit tests because someone else may need to change your code to add functionality. And it'd be much better if they had your assumptions codified as much as possible so that they don't break your code.

        ken@kasajian.com / www.kasajian.com

        M 1 Reply Last reply
        0
        • J Judah Gabriel Himango

          And a response article from Justin Etheredge: It's OK to write unit tests[^].

          Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon Judah Himango

          K Offline
          K Offline
          Kenneth Kasajian
          wrote on last edited by
          #37

          Eventually, computer languages will be designed such that you're encouraged, if not required, to write a test first for a piece of code before you write the code.

          ken@kasajian.com / www.kasajian.com

          1 Reply Last reply
          0
          • K Kenneth Kasajian

            You're absolutely right. A unit test can only verify the programmer's assumptions, which is why it's never going to be enough, and you need a separate person to run the functional and exploratory tests. Don't downplay unit-testing because of this fact. No one is saying unit tests are the only tests. You're using a staw-man argument. If you write the code perfectly the first time, without unit tests, you still need unit tests because someone else may need to change your code to add functionality. And it'd be much better if they had your assumptions codified as much as possible so that they don't break your code.

            ken@kasajian.com / www.kasajian.com

            M Offline
            M Offline
            Mateusz Jakub
            wrote on last edited by
            #38

            I don't want to downplay writing unit tests at all but only writing unit tests to your code, if someone else writes it, then problem stated in article, as I understand doesn't exist.

            1 Reply Last reply
            0
            • K Kenneth Kasajian

              Well, maybe it's not a competency issue. You can do it. But you don't want to. Is it because you don't find it valuable? Also, even if this software isn't a great candidate to be unit tested, there would still be value in having a suite of automated functional tests to validate it's functionality. This would help you if you need to test your product with different versions of Office, including future ones. It's also easier to transfer your code to another programmer, even an intern. You can trust that they probably won't screw things up too bad as long as your tests are run with whatever changes they make (within reason. tests can't catch everything.) If you were to quit the company, it would certainly be easier for someone else to understand and take over your work if there were a great set of automated tests. Is the product moving to a maintenance phase where others have to support it for years to come? Think of those maintenance programmers, who may be outsourced. However, even without functional testing, there's logic in your code that is independent of the user interface which could benefit from being unit tested. It's a lot of work, without direct benefit to that sales guy that you showed the report to, and harder to justify your time doing. A lot of great reasons not to do the right thing, which is why so many people don't do it. In the end, this is a management issue. If the managers don't require programmers to deliver on automated tests, then they won't get it, and they're the ones that will ultimately suffer. If they do require it, the programmer really won't have much of a choice, unless he doesn't want to get a paycheck.

              ken@kasajian.com / www.kasajian.com

              M Offline
              M Offline
              MidwestLimey
              wrote on last edited by
              #39

              You're still thinking solely along engineering lines. This is irrelevant to the situation I described. What MAY happen in the future is a probability, it is a calculated risk. Also you're weighing time spent developing now as equal to time spent developing in the future. This is wrong. Time spent now is more expensive then time spent in the future. Time spent now solving or mitigating theoretical future upgrades is much much much more expensive then time spent in the future fixing it. This is perhaps because you're seeing the software project as the be all and end all. It's not, the product helps others perform their tasks more effectively thereby improving their productivity and reducing costs. Cost savings net overtime and can be allocated into more productive tasks netting an even higher ROI. Delaying a product with the aim of producing perfect testing reduces the potential ROI by constraining the time the productivity boost would otherwise have to work. This ultimately will cost more than fixing issues in the future. In the end it's up to the project sponsers to weigh these competing factors and decide the most reasonable path. Creating unit tests, though feasible, for a reporting engine was simply not cost effective. Unit testing seems to have become the new Gospel of testing over the last 5 or 6 years, but like all IT holy crusades it was led solely by an Engineering mindset whilst ignoring that ever annoying bogeyman we like to call the real world.

              10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011

              K 1 Reply Last reply
              0
              • K Kenneth Kasajian

                You're right. Unit testing makes it easier to replace developers. Is that a bad things? So are you saying you won't write unit tests so that you're not as easily replaceable? The more you're difficult to replace, the more you're like to be stuck at the same job.

                ken@kasajian.com / www.kasajian.com

                M Offline
                M Offline
                Member 96
                wrote on last edited by
                #40

                Kenneth Kasajian wrote:

                So are you saying you won't write unit tests so that you're not as easily replaceable?

                Nope, personally I don't write unit tests because I work in a small shop with very experienced developers and we have a very good and thorough testing team and we can't afford the overhead because the benefit does not outweigh the cost. We tested that method of development and it turned out to be redundant for us, too slow and time consuming and caught none of the typical bugs that we normally always see anyway which are highly complex interactions between things caused by users doing the unexpected and unanticipated. My primary problem with many modern development methodologies is not that they make developers easily replaceable, that's just a side effect of my primary concern which is that they commoditize developers. In other words they reduce what used to be the job of a skilled and experienced craftsman to a job that can be done by any idiot with minimal experience. This drives down the value of all developers everywhere, i.e. salaries, job security and it often results in software that is less than exceptional. It's a method of risk aversion and risk aversion is pretty much everything that is wrong with every creativity based industry these days. It's why you predominantly get bland remakes of movies with the same small set of actors as every other movie instead of new compelling movies with new talent. In the end I suspect it's really not saving software houses any money in the long run commoditizing development. One highly skilled and talented and experienced developer is worth a whole team of cheap developers. Ask any experienced restaurateur whether they can put out more dishes of high quality with a huge brigade of average cooks or a very small highly skilled team and there's no comparison. Something the hospitality industry has known for centuries but the software development industry seems determined to ignore. The problem for software houses is they are afraid to have so much riding on so few people, i.e. risk averse. And no one is ever stuck at the same job, we do have free will after all. :) A highly skilled developer can get work they truly enjoy in any circumstances.


                "Creating your own blog is about as easy as creating your own urine, and you're about as likely to find someone else interested in it." -- Lore Sjöberg

                K 1 Reply Last reply
                0
                • M MidwestLimey

                  You're still thinking solely along engineering lines. This is irrelevant to the situation I described. What MAY happen in the future is a probability, it is a calculated risk. Also you're weighing time spent developing now as equal to time spent developing in the future. This is wrong. Time spent now is more expensive then time spent in the future. Time spent now solving or mitigating theoretical future upgrades is much much much more expensive then time spent in the future fixing it. This is perhaps because you're seeing the software project as the be all and end all. It's not, the product helps others perform their tasks more effectively thereby improving their productivity and reducing costs. Cost savings net overtime and can be allocated into more productive tasks netting an even higher ROI. Delaying a product with the aim of producing perfect testing reduces the potential ROI by constraining the time the productivity boost would otherwise have to work. This ultimately will cost more than fixing issues in the future. In the end it's up to the project sponsers to weigh these competing factors and decide the most reasonable path. Creating unit tests, though feasible, for a reporting engine was simply not cost effective. Unit testing seems to have become the new Gospel of testing over the last 5 or 6 years, but like all IT holy crusades it was led solely by an Engineering mindset whilst ignoring that ever annoying bogeyman we like to call the real world.

                  10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011

                  K Offline
                  K Offline
                  Kenneth Kasajian
                  wrote on last edited by
                  #41

                  Time spent now is a lot cheaper than time spent in the future. This is not about designing for features that don't yet exist. This is about developing a complete solution for the software you're delivering now. Maintainability is built-in, not added on, so are pretty much every other non-functional requirement.

                  ken@kasajian.com / www.kasajian.com

                  M 1 Reply Last reply
                  0
                  • K Kenneth Kasajian

                    I think you're missing the point. A unit test ultimately tries to validate the functionality of a single piece of code. Imagine a method being a math function. You simply want to validate that *that* code is correct, not the rest of the system. So you do that by mocking everything around it. It's a bad argument to say that by doing a unit test it doesn't test how the code works integrated with the rest of the system, therefore a unit test is not useful. No one is saying that the unit test is the only test for code. In fact, some argue that's not even a "test", but a way to verify the the design. You still need integration, functional, exploratory tests, etc.

                    ken@kasajian.com / www.kasajian.com

                    C Offline
                    C Offline
                    CPallini
                    wrote on last edited by
                    #42

                    Kenneth Kasajian wrote:

                    So you do that by mocking everything around it.

                    That's very arguable.

                    Kenneth Kasajian wrote:

                    In fact, some argue that's not even a "test", but a way to verify the the design. You still need integration, functional, exploratory tests, etc.

                    I consider it a test.

                    Kenneth Kasajian wrote:

                    You still need integration, functional, exploratory tests, etc.

                    I know that. My point was against 'academic' approach to unit testing in real systems. :)

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

                    1 Reply Last reply
                    0
                    • M Member 96

                      Kenneth Kasajian wrote:

                      So are you saying you won't write unit tests so that you're not as easily replaceable?

                      Nope, personally I don't write unit tests because I work in a small shop with very experienced developers and we have a very good and thorough testing team and we can't afford the overhead because the benefit does not outweigh the cost. We tested that method of development and it turned out to be redundant for us, too slow and time consuming and caught none of the typical bugs that we normally always see anyway which are highly complex interactions between things caused by users doing the unexpected and unanticipated. My primary problem with many modern development methodologies is not that they make developers easily replaceable, that's just a side effect of my primary concern which is that they commoditize developers. In other words they reduce what used to be the job of a skilled and experienced craftsman to a job that can be done by any idiot with minimal experience. This drives down the value of all developers everywhere, i.e. salaries, job security and it often results in software that is less than exceptional. It's a method of risk aversion and risk aversion is pretty much everything that is wrong with every creativity based industry these days. It's why you predominantly get bland remakes of movies with the same small set of actors as every other movie instead of new compelling movies with new talent. In the end I suspect it's really not saving software houses any money in the long run commoditizing development. One highly skilled and talented and experienced developer is worth a whole team of cheap developers. Ask any experienced restaurateur whether they can put out more dishes of high quality with a huge brigade of average cooks or a very small highly skilled team and there's no comparison. Something the hospitality industry has known for centuries but the software development industry seems determined to ignore. The problem for software houses is they are afraid to have so much riding on so few people, i.e. risk averse. And no one is ever stuck at the same job, we do have free will after all. :) A highly skilled developer can get work they truly enjoy in any circumstances.


                      "Creating your own blog is about as easy as creating your own urine, and you're about as likely to find someone else interested in it." -- Lore Sjöberg

                      K Offline
                      K Offline
                      Kenneth Kasajian
                      wrote on last edited by
                      #43

                      It's not risk aversion, it's risk mitigation, which is accepting whatever that would introduce the risk, but you mitigate against it. The cost of developers finding a bug and fixing it is always less expensive than software testers doing the same. Let them find the problems you cannot find. If there's a bug you can find by writing an isolated unit test, it would be more expensive if that test were to pass through to software test, and have them have to find it, reproduce it, write down the repeat steps, create an incident in a bug tracking system, then you fixing it, then they have to verify that you fixed it. When you increase the length of development by adding more time for developers to write unit tests, it's a much more predictable % increase, then if you were to deliver more buggy code software test. It's hard for them to predict how long their test cycle is going to be at the start of the project, when no code has been written. They have to predict how many additional cycles are required, which is based on how well the previous cycles went. Cycles 2 and on are extremely difficult to predict. In the end the cost of the project may be the same, but spending it in the more predictable stage of the project enables you to have more predictable release dates, which in the end, saves more money for the company.

                      ken@kasajian.com / www.kasajian.com

                      M 1 Reply Last reply
                      0
                      • K Kenneth Kasajian

                        Time spent now is a lot cheaper than time spent in the future. This is not about designing for features that don't yet exist. This is about developing a complete solution for the software you're delivering now. Maintainability is built-in, not added on, so are pretty much every other non-functional requirement.

                        ken@kasajian.com / www.kasajian.com

                        M Offline
                        M Offline
                        MidwestLimey
                        wrote on last edited by
                        #44

                        Not if it delays deployment, and not if deployment is delayed to mitigate what *might* happen. Seesh, please read the replies. Time spent building a decent architecture may reduce future costs if you have a good idea of what will be required. If not it won't since you're designing against what might be there, and so far as I know there isn't a recognized profession of Clairvoyent Software Engineer. Similarly spending significant extra time developing unit tests of no immediate value to the client costs more than future fixes if it forces delays in deployment. Sales Persons had no reliable way of dynamically generating reports in the field. That means lost sales. That means lost revenue. That means lost profit. It's nice that you want to reduce the work load on future developers, but ultimately it's *probable* future work thus not real work or therein a real cost. It's considered a fractional cost as it's a risk and not an absolute which again makes work now more expensive. I feel supremely confident that I'm a good source to verify that CBA decision was a good one since I was actually there and helped make it. Apparently you were there too and disagreed? I'm sorry I don't remember you. All code dealing directly with the automation objects were abstracted to well documented classes. This was deemed sufficient to mitigate future risk. If you can recall what your viewpoint was at the meeting, please remind me ...

                        10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011

                        1 Reply Last reply
                        0
                        • K Kenneth Kasajian

                          It's not risk aversion, it's risk mitigation, which is accepting whatever that would introduce the risk, but you mitigate against it. The cost of developers finding a bug and fixing it is always less expensive than software testers doing the same. Let them find the problems you cannot find. If there's a bug you can find by writing an isolated unit test, it would be more expensive if that test were to pass through to software test, and have them have to find it, reproduce it, write down the repeat steps, create an incident in a bug tracking system, then you fixing it, then they have to verify that you fixed it. When you increase the length of development by adding more time for developers to write unit tests, it's a much more predictable % increase, then if you were to deliver more buggy code software test. It's hard for them to predict how long their test cycle is going to be at the start of the project, when no code has been written. They have to predict how many additional cycles are required, which is based on how well the previous cycles went. Cycles 2 and on are extremely difficult to predict. In the end the cost of the project may be the same, but spending it in the more predictable stage of the project enables you to have more predictable release dates, which in the end, saves more money for the company.

                          ken@kasajian.com / www.kasajian.com

                          M Offline
                          M Offline
                          Member 96
                          wrote on last edited by
                          #45

                          I agree with the stipulation that you're describing a large company with cheap developers. In a small company with expensive developers the entire scenario is turned upside down.


                          "Creating your own blog is about as easy as creating your own urine, and you're about as likely to find someone else interested in it." -- Lore Sjöberg

                          1 Reply Last reply
                          0
                          • N Nemanja Trifunovic

                            Deyan Georgiev wrote:

                            I think this entire “unit testing” madness originates from Java

                            IMHO, it is from Smalltalk - switched to Java folks. The same crowd that invented "Extreme Programming", "Design Patterns", etc. Anyway, I am happy to see that even Java programmers are comming to their senses[^]

                            utf8-cpp

                            D Offline
                            D Offline
                            dmitri_sps
                            wrote on last edited by
                            #46

                            Nemanja Trifunovic wrote:

                            The same crowd that invented "Extreme Programming", "Design Patterns", etc.

                            I thought these were two opposite crowds. XP was from PHP etc developers, Patters were from C++ & Java world

                            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