Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.

- Stackoverflow.com Wiki
25 articles, 5 books. Go to books ↓

Every time when I write code, I remember that my customer (and the users of the application) trust me. They expect that the application provides correct information to them. They expect that the information entered to the application is safe, and it cannot be accessed by unauthorized persons.


Most programmers do not write tests. We all know that we should write them, but for whatever reason, most of us don't. This is unfortunate, because testing is the most powerful tool we know of to improve software quality. Tests reduce bugs, provide accurate documentation, and improve design.


Testing approaches depend on where you are in the project and your “budget,” in terms of time, money, manpower, need, etc. Ideally, unit testing is budgeted into the development process, but realistically, we often encounter existing or legacy programs that have little or no code coverage but must be upgraded or maintained.


This article will present ways to design and refactor code for better testability, and demonstrate how this will influence the tests. The solutions are applicable to code that takes advantage of async and await, as well as code based on lower-level multithreading mechanisms from earlier frameworks and libraries.


There is a pattern I really don't want to see in unit tests. I will call this the I-have-no-idea-what-I-am-testing-anti-pattern. The anti-pattern is easily spotted because the test code itself contains calls to your service locator to resolve interfaces.


A look at how to unit test code that makes use of Repository vs using raw Entity Framework, where we will do this using mocks/test doubles.


Dear developer, I’ve been wanting to talk to you for a while now, but words don’t always come easy. We’ve had some really fun times together. I still remember the first time I warned you about a minor bug in your code, and how happy you were for having me in your life! Do you remember it? I also remember the first time you refactored me to make me more efficient and how well-written I felt afterwards... ah, great times!


Many guides out there will encourage you to add some lines in your “build.gradle” to enable “instrument tests” and also tell you to include the Android testing libraries in your dependencies… This is completely unnecessary and you won’t need to worry about doing that.


The default test runner for Angular is Karma, which makes sense as it was written by them. There are several options out there for the framework, and I personally prefer using Mocha as it runs on Node.js.


Unit tests are definitely becoming a need-to-have skill for developers to confirm their code does what it should for production.


This should be an easy question to answer, right? Turns out that there are several definitions of unit testing, and even though they are similar, they are also different enough that answering this question is difficult.


Most developers seem to agree that testing is good, but developers frequently disagree about how to test.


If you were to take a poll of software development shops and ask whether or not they unit tested, you’d get varied responses. Some would heartily say that they are, and some would sheepishly say that they totally mean to get around to that next year and that they’ve totally been looking into it. In the middle, you’d get a whole lot of responses that amounted to, “it’s complicated.”


Unit tests make it much easier to change our code while making sure we don't change its behavior (refactoring). This means that properly unit tested code can be heavily refactored/cleaned up so if we happen to break existing functionality we'll know instantly by way of failing tests.


Unit testing is of course not just an issue in object-oriented programming, but the combination of object-orientation, agile software development, and a rise in tools and computing power has made it de rigueur.


Unit testing is an essential instrument in the toolbox of any serious software developer. However, it can sometimes be quite difficult to write a good unit test for a particular piece of code. Having difficulty testing their own or someone else’s code, developers often think that their struggles are caused by a lack of some fundamental testing knowledge or secret unit testing techniques.


There's a sweet spot with unit testing -- and most dev teams are missing it


Remember that actors interact only using message passing. In order to check actors behavior you can do it through the messages sent to them and back from them. So how do you test actors? You send them messages :) To test actors that communicate only with messages, you need to send it a message and get reply back and check it.