How important is Unit Testing taken by employers, is it something that every developer should have as one of their skills, do some jobs require it more than others or is a simple test like handing out a piece of software to be used by friends family etc sufficient enough.

Given that Unit Testing, or some equivalent testing method, is the only way to locate errors in the untyped PHP language I would assume serious employers would consider it a necessary skill.

@Full Spectrum
Its not an untyped language it is a loosely typed language. You can cast values to a particular type and do type comparisons if you want/need too.

@benjaminFowl87
Unit testing is a very powerful mechanism for development, but in my experience it is a different mindset than just sitting down and writing code. Generally you see unit testing talked about with TDD (Test Driven Development). In other words, you design your functionality, write a failing test, write code to pass the test and finally refactor the code to a certain standard level.

Unit testing really shines when you have a system that is heavily tested and then you are tasked with making changes to already existing classes/functions throughout the existing system. Because your tests all pass to start, you write new failing tests and then implement the code necessary to pass those tests. As long as your original tests still pass and your new tests pass, then you have added your additional functionality without breaking any existing code.

Where as without testing, its next to impossible to know for sure that everywhere that piece of code is used is still functional until a bug or issue is found.

Just my $0.02 hope it helps.

Unit testing is testing that is designed to verify individual modules (functions, classes, etc.) at a low level, to verify that module is behaving as specified. You usually use stubs or mock objects in unit tests, which keep the module isolated and do not rely on all of the other parts of the program.

It is separate from other types of testing like integration testing, where the modules are combined to make sure they are behaving together. The idea is that if each individual component is tested and works correctly, and you do not get the correct result when they are combined, then the problem is with the integration and not the modules.

It's important because it simplifies integration testing by verifying individual parts first. It is absolutely critical in certain types of development, like test-driven development, where you create tests first, and then write the code that makes the tests pass. It is also helpful in allowing developers to refactor code because the unit tests can be used to verify that the functionality is still consistent with the old code. Finally, it increases code coverage of your test suite, because it can allow you to exercise parts of the code that may not be immediately reachable in standard scenarios.

Unit tests:

  • Let you validate your component design in isolation, making it easier to debug when there's a problem.
  • Let you test functionality which is either not exposed or not easily accessible from the program's external interfaces, for example error handling and functionality which has no UX yet.
  • Provides a cheap way to ensure you haven't broken any major existing functionality across the system when you make cross-component changes.
  • Provides a way for people unfamiliar with your code to verify they haven't broken it when they are working with it. And, for them to see how it works.
  • Automates what might otherwise be arduous manual testing. It helps keep you from getting lazy and not testing the impact of changes.

Testing is an investment. If your code will be around for a while, or have other people using it, it's an investment well worth making. If your code will only ever be used by you, and isn't relied upon by a business, well, do whatever you like.

commented: Please be timely. This discussion is 9 years old. +0