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)

7
votes
6answers
757 views

How do you unit test an encoder?

I have something like this: public byte[] EncodeMyObject(MyObject obj) I've been unit testing like this: byte[] expectedResults = new byte[3]{ 0x01, 0x02, 0xFF }; Assert.IsEqual(expectedResults, ...
6
votes
2answers
247 views

How to do unit tests on a method that takes the elapsed time into account?

I'm currently in the middle of refactoring an important method in a legacy-system. There were almost zero test until I've started working on it, and I've added quite a lot to ensure the correct work ...
5
votes
2answers
2k views

Event Driven Programming: A sequence of unfortunate events

I have a very basic game loop whose primary purpose is to check for updates & changes to a list. I have contemplated using event driven programming to replace the game loop/list idea with an ...
8
votes
3answers
679 views

Relative value of manual vs automated testing

The organisation I work for has recently employed a testing officer to run manual tests, but when I asked about being given time as a developer to write unit tests the response was that the manual ...
9
votes
2answers
297 views

Should I refactor my unit tests when I extract a class out of the System Under Test?

I wrote this class that does a few things (perhaps this is a violation of the Single Responsibility Principle). I realize now that some other part of the project needs a piece of that logic and the ...
5
votes
2answers
347 views

When to write Unit Tests : Is there any or list of terms to take right decision [closed]

To write Unit Tests we have to write extra bits of code. For several projects we do Unit Tests and for several projects we do not. As a Team Leader I face trouble to make the right decision. Is ...
6
votes
2answers
2k views

Helper static methods in TDD

I am creating an application which will be testable(unit + integration). In this application I have a FileHelper static class, public static class FileHelper { public static void ...
5
votes
2answers
401 views

Write tests for unit tests in TDD?

In an answer to another question, I suggested creating a randomized value for input to a specific method. In my experience this has been useful for making tests more readable and it lets you skip the ...
3
votes
2answers
5k views

JUnit Testing in Multithread Application

This is a problem me and my team faces in almost all of the projects. Testing certain parts of the application with JUnit is not easy and you need to start early and to stick to it, but that's not the ...
4
votes
5answers
2k views

Is path coverage stronger than condition coverage?

I have encountered (even in literature) two contradicting opinions related to path vs condition coverage (not branch or edge!). Some say Path coverage is stronger than the condition coverage, some say ...
147
votes
16answers
12k views

Why does automated testing keep failing in my company?

We have tried to introduce developer automated testing several times at my company. Our QA team uses Selenium to automate UI tests, but I always wanted to introduce unit tests and integration tests. ...
31
votes
6answers
3k views

How should you TDD a Yahtzee game?

Let's say you're writing a Yahtzee game TDD style. You want to test the part of the code that determines whether or not a set of five die rolls is a full house. As far as I know, when doing TDD, you ...
5
votes
7answers
372 views

Test driven development when implementing a flexible length list

According to the commonly used TDD strategy, to implement something, you write a test that fail the code first, write the simplest code, refactor, and then repeat. I am trying to imagine this scenario ...
12
votes
2answers
554 views

How do I know if I have enough unit test coverage to remove an integration test?

I'm working on a legacy system (by that I mean it was written without tests). We've tried to test some of the system by writing integration tests that test functionality from the outside. This ...
4
votes
4answers
2k views

Why do I need unit tests for testing repository methods?

I need to play devils advocate on this question a bit because I cannot defend it well because of lack of experience. Here is the deal, I get conceptually the differences between unit testing and ...
6
votes
2answers
808 views

Unit Test Friendly Domain Driven Design

Many of the readings I've done on DDD, both in books and online, seem to represent code that, often times, is difficult or impossible to unit test. For example, there are numerous samples with static ...
3
votes
3answers
384 views

Is unconditional code considered a branch?

Having simple code like this: int A=5; object X=Console.ReadLine() if(Condition) DoSomething(); else DoStuff(); DoSomethingElse(); Some sources say there are actually 4 branches: First ...
2
votes
1answer
224 views

Specifying Query in Unit Test

When writing unit tests, should I specify the query that will be performed for interacting with the database? I can see both sides of this. On one hand, I want to make sure that the query that I ...
9
votes
6answers
2k views

Best practices for unit testing methods that use cache heavily?

I have a number of business logic methods that store and retrieve (with filtering) objects and lists of objects from cache. Consider IList<TObject> AllFromCache() { ... } TObject ...
2
votes
1answer
187 views

Unit Testing Open Source projects that require keys for api calls

What's the recommended method for setting up tests on code that requires a private key to make calls to external web services? Full on mock objects or is there a way of distributing open source unit ...
25
votes
11answers
5k views

How do we make unit tests run fast?

We have reached the point in our project where we have almost a thousand tests and people have stopped bothering with running them before doing a check in because it takes so long. At best they run ...
11
votes
3answers
586 views

Is using unit tests to tell a story a good idea?

So, I have an authentication module I wrote some time ago. Now I'm seeing the errors of my way and writing unit tests for it. While writing unit tests, I have a hard time coming up with good names and ...
1
vote
2answers
116 views

Name for intentionally assertless unit test [closed]

I have a tool that is going to be run as part of commit stage on Continuous Integration server to check whether all unit tests run do have an assert. Its main purpose is to eliminate silly mistakes ...
4
votes
2answers
120 views

Unit testing markup building logic

I'm currently writing a library of helper functions to produce some repetitive markup. I have a reference to the markup the functions should produce, but I'm curious about how I should go about unit ...
5
votes
2answers
270 views

Is it ok to use static (compile-time) assertions in unit tests?

Or more generally: to trigger compiler errors in test projects if something that can be checked at compile time is wrong?
4
votes
7answers
446 views

Should I spend time prettifying unit tests? [closed]

The company I used to work for before we had automated unit tests to test our work. However the coding standards and architecture was not very important for tests. Of course you had to indent code ...
5
votes
3answers
494 views

How much to test in TDD?

I am newbie to TDD (writing first project following TDD practices). I have fairly basic interface IProfiler and an implementation Profiler. interface IProfiler { bool IsBusy {get;} long Elapsed ...
26
votes
5answers
3k views

Why is it often said that the test cases need to be made before we start coding? [duplicate]

Why is it often said that the test cases need to be made before we start coding? What are its pros and what the cons if we don't listen to this advice? Moreover, does that advice refer to black box ...
18
votes
3answers
4k views

Should I still use Debug.Assert today?

I recently came across some newly written code that was interspersed with lots of Debug.Assert (C#). Should we still use this widely despite the usage of TDD, BDD and Unit Testing in general?
3
votes
1answer
585 views

How to structure unit testing of huge libraries?

I am writing unit tests for a library written in Qt/C++. The library is rather big, with lots of functionalities. I have a separate unitTest folder which I have my UnitTest.cpp in there. Having all ...
6
votes
3answers
2k views

Behavior Driven Development and Unit Testing in Python

We might be interested in starting to incorporate a unit test suite to our project, which is coded in Python (and it uses Redis, PostgreSQL and some third-party libraries, if that bears into the ...
6
votes
2answers
447 views

Unit Testing and Asserting

Assume we have a method that validates an object before saving it to a DB. It returns back KVP something like: public KeyValuePair<bool, List<FooErrorReason>> ValidateABar(Bar b) { ...
10
votes
2answers
262 views

How would type errors be detected while creating mocks in a dynamic language?

The problem occurs while doing TDD. After a couple of test pass, the return types of some class/module change. In a statically typed programming language, if a previous mocked object was used in the ...
3
votes
1answer
436 views

TDD and test automation in applications heavily dependent on databases and user input [closed]

Recently I have been reading online about eXtreme programming and agile practices. I wish to adapt them. However most of my code is all in PHP which is the normal CRUD type web applications. Moreover ...
7
votes
3answers
865 views

Unit Testing DatabaseOpenHelper class in Android

I've written several unit tests for an already existing DatabaseOpenHelper class. I covered the creation scenario and migration from old schema to new one. Unfortunately, I don't feel that my tests ...
10
votes
5answers
739 views

Is adhering to one assert per test foolish consistency in this case?

I have a class that I'm testing. The class has a function: apply(List<IRule> rules, List<ITarget> targets); In one test I want to ensure that each target has been passed to one rule, a ...
6
votes
1answer
107 views

Is there ever a reasonable time to have test fixtures test MVC3 controller construction?

I've recently started with a new firm and I'm trying to understand the mechanics behind something, so I'll anonymize the code and present but a sample: [Test(Description = "Retreives the New view for ...
8
votes
5answers
424 views

What are tangible advantages to proper Unit Tests over Functional Test called unit tests

A project I am working on has a bunch of legacy tests that were not properly mocked out. Because of this the only dependency it has is EasyMock, which doesn't support statics, constructors with ...
2
votes
1answer
180 views

Link between tests and user stories

I have not see these links explicitly stated in the Agile literature I have read. So, I was wondering if this approach was correct: Let a story be defined as "In order to [RESULT], [ROLE] needs to ...
4
votes
1answer
181 views

Using NSpec at various architectural layers

Having read the quick start at nspec.org, I realized that NSpec might be a useful tool in a scenario which was becoming a bit cumbersome with NUnit alone. I'm adding an OAuth (or, DotNetOpenAuth) to ...
5
votes
2answers
7k views

Does Visual Studio 2012 Express support NUnit tests? [closed]

I am currently using Visual Studio Express 2012 Desktop (the free version). I now have received source code with NUnit tests included. I can not bring them to run with Visual Studio (not seeing them ...
8
votes
4answers
748 views

Is it useful to unit test methods where the only logic is guards?

Say I have a method like this: public void OrderNewWidget(Widget widget) { if ((widget.PartNumber > 0) && (widget.PartAvailable)) { ...
2
votes
2answers
245 views

Unit test and Code Coverage of Ant build scripts

In our development environment We have more and more build scripts for ant to perform the build tasks for several different build jobs. These build scripts sometimes become large and do a lot of ...
13
votes
4answers
1k views

If you should only have one assertion per test; how to test multiple inputs?

I'm trying to build up some test cases, and have read that you should try and limit the number of assertions per test case. So my question is, what is the best way to go about testing a function w/ ...
8
votes
3answers
1k views

Mocking concrete class - Not recommended

I've just read an excerpt of "Growing Object-Oriented Software" book which explains some reasons why mocking concrete class is not recommended. Here some sample code of a unit-test for the ...
4
votes
3answers
421 views

Should adapters or wrappers be unit tested?

Suppose that I have a class that implements some logic: public MyLogicImpl implements MyLogic { public void myLogicMethod() { //my logic here } } and somewhere else a test class: ...
8
votes
5answers
558 views

How to TDD test that objects are being added to a collection if the collection is private?

Assume that I planned to write a class that worked something like this: public class GameCharacter { private Collection<CharacterEffect> _collection; public void Add(CharacterEffect e) ...
-2
votes
2answers
550 views

How can I test database access methods in Java? [closed]

I want to write a test for a method that accesses a database such as following. public class MyClass{ public String getAddress(Int id){ String query = "Select * from Address where ...
1
vote
1answer
267 views

Unit test: How best to provide an XML input?

I need to write a unit test which validates the serialization of two attributes of an XML(size ~ 30 KB) file. What is the best way to provide an input for this test? Here are the options I have ...
0
votes
1answer
292 views

Control flow testing in white box - static or dynamic?

Yesterday I asked a question that happened to have another meaning inside. I can see that Control/data flow is often mentioned to be static analysis (when tools is used) or dynamic analysis testing in ...