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

learn more… | top users | synonyms (1)

13
votes
3answers
991 views

How would you unit-test or perform the most effective automated testing on graphics code for OpenGL?

I'm writing a game and the accompanying graphics engine on top of OpenGL in C++. Im also a fan of good coding processes and automated testing. Graphics code + testing seems pretty immiscible, since ...
7
votes
3answers
665 views

Interfacing application code with unit tests

I am working on a project in which we have to implement and unit test some new module. I had a quite clear architecture in mind so I quickly wrote down the main classes and methods and then we started ...
5
votes
1answer
704 views

How to unit test large legacy systems? [duplicate]

Possible Duplicate: Best practices for retrofitting legacy code with automated tests When working in large legacy systems (large systems with no unit testing ever) I often come across ...
9
votes
5answers
2k views

Is unit testing procedural code effective?

On a current project, the powers that be want to have unit testing incorporated into our development cycle to avoid the constant amount of bugs that seem to seep into our code. The problem is that the ...
3
votes
4answers
766 views

Testing thread safety

Say you have a function f that is or contains a critical section. How would you unit test that only one thread can run it at once, that it doesn't have race conditions, and that it doesn't cause a ...
8
votes
6answers
497 views

How to use unit tests as a source of information?

A colleague of mine was once at a seminar about agile development, where he heard it is possible to use unit tests as technical documentation. Something like using unit tests as an example of how to ...
1
vote
2answers
72 views

Should Multiple Data Items be in Multi Unit Test Methods?

I often want to have the same unit test applied to data multiple items that are roughly equivalent (two non-empty strings). Currently I implement these in multiple unit test methods, with names like ...
2
votes
4answers
204 views

Testing a file that relies heavily on a static array

I have a .c file that basically manages its own little database of people. There are add, remove, edit and search functions among some others. It has a static array which it uses to store the data. ...
1
vote
2answers
499 views

Looking for good testing in multithreaded C or C++ open source projects [closed]

I have read a lot about the importance of unit testing, and testing in general. In particular I have read about TDD which, in theory, seems like a good way to ensure effective test coverage for a ...
46
votes
10answers
6k views

How should I test randomness?

Consider a method to randomly shuffle elements in an array. How would you write a simple yet robust unit test to make sure that this is working? I've come up with two ideas, both of which have ...
9
votes
5answers
2k views

switch statement - handling default case when it can't be reached

If I'm using a switch statement to handle values from an enum (which is owned by my class) and I have a case for each possible value - is it worth adding code to handle the "default" case? enum ...
4
votes
4answers
343 views

Unit testing: about easy- and hard-first strategies

I've never written a unit test. I'm reading The art of Unit Testing by Osherove, and he explains a way to choose where to start when you're writing tests for legacy code. Basically you end up with ...
67
votes
16answers
9k views

When is unit testing inappropriate or unnecessary? [duplicate]

It seems to be generally assumed (on Stack Overflow at least) that there should always be unit tests, and they should be kept up to date. But I suspect the programmers making these assertions ...
6
votes
6answers
2k views

Can the Strategy pattern be implemented without significant branching?

The Strategy pattern works well to avoid huge if...else constructs and make it easier to add or replace functionality. However, it still leaves one flaw in my opinion. It seems like in every ...
4
votes
1answer
625 views

What and how to unit test a django web application?

I am writing unit tests for a web frontend implemented in Django. I have written unit tests that check that all views return the correct status code (200, 302 etc) so that template errors (which give ...
17
votes
4answers
675 views

How do I write unit tests for robots (and other mechanical devices)?

I'm a member of my high school's robotics club, and am responsible for programming the robot. One suggestion I keep hearing from various adults is that I should be writing unit tests to help validate ...
2
votes
1answer
311 views

Virtual Machines And Unit/Integration Testing Web Application

I am in the process of adding unit testing to a project I am working on at work and a suggestion came up that I should use VMs to populate the database with good data. This was suggested as an ...
15
votes
3answers
3k views

Real-world examples of apps written with TDD and good test coverage? [closed]

Are there any open source applications that are developed using test driven development that serve as models of how good unit testing should work? I'd prefer to see examples in C# and .NET. (Note ...
0
votes
3answers
363 views

Is Debug.Assert obsolete if you write unit tests?

Just like the question asks, is there a need to add Debug.Assert into your code if you are writing unit tests (which has its own assertions)? I could see that this might make the code more obvious ...
4
votes
8answers
493 views

Testing loses its effectiveness if all programmers don't use them

Let's assume you are convinced that the extra time spent unit testing has merit and improves production. Does that still hold up when everyone working on the same code doesn't use them? This question ...
0
votes
1answer
77 views

Compatibility Test and other testing method to use while building software

I will be adding a feature to the software and have to update or modify some of public API of the present open source software. What are steps which could be taken to ensure the compatibility of the ...
2
votes
3answers
471 views

Development processes, the use of version control, and unit-testing [closed]

Preface I've worked at quite a few "flat" organizations in my time. Most of the version control policy/process has been "only commit after it's been tested". We were constantly committing at each ...
5
votes
2answers
183 views

CI tests to enforce specific development rules - good practice?

The following is all purely hypothetical and any particular portion of it may or may not accurately describe real persons or situations, whether living, dead or just pretending. Let's say I'm a ...
0
votes
2answers
2k views

Should I use a seperate class per test?

Taking the following simple method, how would you suggest I write a unit test for it (I am using MSTest however concepts are similar in other tools). public void MyMethod(MyObject myObj, bool ...
48
votes
16answers
3k views

Why not write all tests at once when doing TDD?

The Red - Green - Refactor cycle for TDD is well established and accepted. We write one failing unit test and make it pass as simply as possible. What are the benefits to this approach over writing ...
4
votes
2answers
845 views

How and what should I be (unit) testing for in this method?

I am relatively new to unit testing and have a query about what/how I should be testing a certain method. For the following (psudo-c#) method I have created (not a real-life example) what would you ...
0
votes
1answer
673 views

Differences between software testing processes and techniques?

I get confused between these terms. For example, should unit testing be listed as a software testing process or technique? I think unit testing is a software testing technique. And how about Test ...
1
vote
4answers
327 views

Is application-specific data required for good unit testing?

I am writing unit tests for a fairly simple function that depends on a fairly complicated set of data. Essentially, the object I am manipulating represents a graph and this function determines whether ...
11
votes
3answers
982 views

What arguments can I use to “sell” the BDD concept to a team reluctant to adopt it?

I am a bit of a vocal proponent of the Behaviour Driven Development methodology (aka BDD). I've been applying BDD for a couple of years now, and have adopted StoryQ as my framework of choice when ...
29
votes
7answers
5k views

Is dependency injection essential for unit testing?

Is using dependency injection (DI) essential for unit testing? I can't think of another alternative for isolating code so it can be tested. Also, all the examples I have ever seen use this pattern. ...
0
votes
1answer
3k views

Implementing a ILogger interface to log data

I have a need to write data to file in one of my classes. Obviously I will pass an interface into my class to decouple it. I was thinking this interface will be used for testing and also in other ...
2
votes
5answers
1k views

Should I use a unit testing framework to validate XML documents?

From http://www.w3.org/XML/Schema: [XML Schemas] provide a means for defining the structure, content and semantics of XML documents. I'm using an XML Schema (XSD) to validate several large XML ...
8
votes
5answers
713 views

Is it OK to repeat code for unit tests?

I wrote some sorting algorithms for a class assignment and I also wrote a few tests to make sure the algorithms were implemented correctly. My tests are only like 10 lines long and there are 3 of ...
3
votes
2answers
1k views

How much extra time is needed to add unit test in a development task?

My team is considering moving to test-driven development. Currently we have almost no unit testing, we have been only relying on the user acceptance test, and developer's own manual test. Not everyone ...
34
votes
10answers
4k views

Is unit testing or test-driven development worthwhile?

My team at work is moving to Scrum and other teams are starting to do test-driven development using unit tests and user acceptance tests. I like the UATs, but I'm not sold on unit testing for ...
1
vote
2answers
2k views

Is there a good example of Python code for unit testing an api? [closed]

Do you know any good example of Python unit testing code for testing an API? Thanks! Update: Found this very interesting question: ...
1
vote
4answers
3k views

How to Console.WriteLine from [TestMethod]?

I am trying to show some information from a [TestMethod] method. Usually we use NUnit and a line with Console.WriteLine runs fine and we can see it in 'output' window, but on this project we must to ...
3
votes
1answer
522 views

How can I test a parser for a bespoke XML schema?

I'm parsing a bespoke XML format into an object graph using .NET 4.0. My parser is using the System.XML namespace internally, I'm then interrogating the relevant properties of XmlNodes to create my ...
12
votes
8answers
831 views

Unit testing - Database coupled app

What would be the best approach at unit testing a model that integrates into an application that is tightly coupled to database? The specific scenario here is a shopping cart - I'd like to be able to ...
3
votes
2answers
141 views

Learning system instead of using sed/replace for reviewing test results

For every build of my software I run it through a series of tests that execute a number of commands on a command line and captures the results. Most of the time the output is a combination of: - ...
2
votes
1answer
145 views

Testing chainable method calls return type and value

Is it worth testing the return type and value of a method call that is designed for chaining? It is conceivable that a fellow programmer could accidentally change the return type to void and remove ...
16
votes
3answers
886 views

Add a unit test for each new bug

In my job all developers that resolve a bug have to add a new unit test that warns about this type of bugs (in the case it occours again). If a unit test is not possible (for example, a webpage design ...
5
votes
4answers
274 views

Type mocking frameworks does not change coding practices from testability point?

Many people recommend that we should code against interfaces and avoid statics for testability. Interfaces are not just for testability, they are sometimes a requirement. But sometimes we introduce ...
14
votes
6answers
1k views

Do I really need a unit test framework?

Currently at my job, we have a large suite of unit tests for our C++ application. However we don't use a unit test framework. They simply utilize a C macro that basically wraps an assert and a cout. ...
6
votes
3answers
569 views

How to simplify my complex stateful classes and their testing?

I am in a distributed system project written in java where we have some classes which corresponds to very complex real-world-business objects. These objects have a lot of methods corresponding to ...
3
votes
1answer
2k views

Unit testing invalid inputs; ArgumentException vs. Custom Exception

In unit tested code I often have multiple checks on the arguments on any method before the actual "work" of the method is begun: public void DoSomething(string test) { if ...
8
votes
7answers
1k views

Creating Unit Tests on a CRUD layer of an Application, how can I make the tests independent?

So I'm trying to make my Unit Tests as by-the-book as possible, but it becomes troublesome when I'm testing some simple Add/Delete methods. For the add method, I basically have to create a dummy ...
3
votes
2answers
204 views

In javascript and other languages which lack a compiler, is unit testing a good method to ensure correct syntax and variable naming?

I've been working on a medium sized web application that makes very heavy use of javascript. I tend to introduce common errors per 10 lines of code with either an unknown variable name or function ...
2
votes
1answer
6k views

How do I use PowerMock / Mockito / EasyMock to use a mocked object for dependency injection?

I have an AuthenticationManager.authenticate(username,password) method that gets called in someMethod of a SomeService under test. The AuthenticationManager is injected into SomeService: @Component ...
5
votes
1answer
1k views

Removing the “integration test scam” - Understanding collaboration and contract tests [closed]

I've recently watched Integration Tests are a Scam by J. B. Rainsberger and am now looking for more material on the subject. I have to say, I'm shocked by how much we're doing wrong, (i.e. integration ...