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)

1
vote
2answers
375 views

Testing ASP.NET .aspx and .ascx code behind files

I am wondering how to test .aspx.cs and .ascx.cs code behind. Can I use unit testing and if so how? Are there alternatives that will help test the functions in the code behind files? I don't know how ...
0
votes
2answers
108 views

Why separate unit tests into an assembly [closed]

I primarily develop in .Net, and have been playing around with F#. It's a nice concise language, but I'm just using it for throwaway code currently. I've taken to sitting my tests in the same file as ...
4
votes
5answers
278 views

Are there any cases when one should not use Test Driven Development? [duplicate]

Is it recommended that TDD be always practiced in a project, or are there cases when it should be avoided? Should we all adopt TDD? Is it standard practice in major software companies?
0
votes
1answer
65 views

testing: which code layers should I aim to test?

Say I have this code: Design { public function load() { $this->loadProduct(); $this->loadService(); ... } public function loadProduct() { ...
2
votes
3answers
234 views

how and should I 'unit test' an entire package?

I'm still learning to be good about doing unit level testing, as I've always been a little sloppy about only doing functional testing in the past, so I want to double check I'm doing this 'right'. I ...
0
votes
1answer
102 views

Am I bound by the license of a library that is used in my project but is not distributed with it?

I want to publish a small open source project on GitHub. I'd like to release it with either MIT or Apache license. The project has unit tests that use JUnit library. JUnit is released with the ...
1
vote
5answers
532 views

Unit Testing a method that contains two output type parameters

I was following a book Art of Unit Testing, This book says that You must not have any logic in Your asserts as this reduces readability of test, or I may be testing too many things at a time. Suppose ...
0
votes
1answer
88 views

How to apply IoC (or something similar) to a constant?

I have the following class with the following members: public class RegistrationPresenter : EPiPresenter<IRegistrationView, LoginPage>, IDisposable { private readonly static string[] ...
3
votes
2answers
191 views

Unit testing behaviours without coupling to implementation details

In his talk TDD, where did it all go wrong, Ian Cooper pushes Kent Beck's original intention behind unit testing in TDD (to test behaviours, not methods of classes specifically) and argues for ...
0
votes
2answers
114 views

Characterization in Testing: Unit test or Functional test [duplicate]

So I'm trying to push for more automated testing in my company, which focus a lot on prototype and proof of concept systems. We currently use Google Test for unit testing. This tests specific test ...
0
votes
2answers
91 views

Best practice to return a long string in a stub

I have some methods im trying to test which use a StreamReader dependency that i mock using Rhino mocks. But it is a large xmlFile. In the spirit of unit testing im trying to keep away from using a ...
2
votes
1answer
81 views

How to simplify unit testing with higher order functions?

this is not a question on how to write unit tests this is not a question on what to test this is a question on reducing the typing needed overall for a personal testing framework I know you can ...
4
votes
2answers
449 views

Unit testing of non-atomic methods [duplicate]

I'm new in unit testing. For last two days I'm thinking how to test non-atomic methods with unit tests. When i need to write tests for some simple, atomic method situation in pretty easy - i'm taking ...
0
votes
3answers
139 views

Isolating unit tests in python

As a 30-year software developer, mostly in OO languages, but a newbie at python, I'm looking to find what is best practise for isolating unit tests in python. Let's say I have the following, ...
1
vote
1answer
78 views

TDD verifying dependency method invoked correctly

I am trying to follow TDD in my proj but I can't get my head around how to verify I am calling a dependency correctly or even if I should be trying to verify it. Here's the requirement: Write an ...
15
votes
6answers
765 views

From a TDD perspective, am I a bad person if I test against a live endpoint instead of a mock?

I follow TDD religiously. My projects typically have 85% or better test coverage, with meaningful test cases. I do a lot of work with HBase, and the main client interface, HTable, is a real pain ...
2
votes
1answer
221 views

Unit test JSON parsing code?

In my humble view of unit testing a unit test tests a single unit of code. For me, this means a single class. Every dependency for that class is mocked in the corresponding test class, and passed in ...
3
votes
2answers
518 views

Unit testing, factories, and the Law of Demeter

Here's how my code works. I have an object that represents the current state of something akin to a shopping cart order, stored in a 3rd party shopping API. In my controller code, I want to be able to ...
0
votes
0answers
47 views

Adding unit tests to brownfield applications [duplicate]

I'm working for a company that has been developing a series of products for years with little to no unit testing in place. They want to move to TDD and unit test new code going forward. However, I'm ...
0
votes
3answers
113 views

Is it possible to have setup and tear down methods run only for specific unittests?

I currently have a test class with a setUp method for creating a temp file and a tearDown method for deleting a temp file. However, only some of the the test_ methods in that class require this ...
1
vote
1answer
112 views

How to introduce testing in the development cycle

In our company, we are only two IT staffs, and I'm the only developper. I'm developping rich intranet applications using plain php and extjs as javascript framework. Our development cycle is usually ...
3
votes
5answers
198 views

Do I need a suite of unit tests for inner business-logic class? Since it's going to replicate the acceptance test suite for 90% [duplicate]

I'm new to TDD and wondering about methodolody. Given: A simple project which implements functionality of, for example, a console calculator. It has the following structure: Fairly simple ...
1
vote
2answers
67 views

Correct Seam for Stub

In Chapter 3 of his book The Art of Unit Testing: with Examples in C#, Roy Osherove illustrates the issue of undesirable external dependencies in code under test. He shows this with a method ...
0
votes
3answers
62 views

Writing tests for two methods that share functionality

I'm writing some tests for a NodeJS module, but this question can apply for any language / platform. I've got the following situation: // in moduleA.js exports.foo = function (var1, var2) { // ...
0
votes
1answer
47 views

Testing the Consumers of Subclassed Data Structures

PHP's SplQueue does not include a clear() or reset() function to wipe data out of the data structure. My application requires that functionality. This leaves two options: A) Create a subclass of ...
6
votes
3answers
382 views

Are “Stocks” a TDD/Unit testing anti pattern?

From Martin Fowler's Mocks Aren't Stubs he states that Stubs provide canned answers to calls made during the test while Mocks objects pre-programmed with expectations which form a specification of the ...
1
vote
2answers
108 views

When changing a class/method and you already have passing unit tests, should you change then test or write a test then change?

Say I have a class with a single constructor that accepts 2 parameters and initialises itself using those parameters. I have written tests for this and they are all passing. I later realise I need to ...
2
votes
4answers
265 views

Is refactoring for the purpose of unit testing a code smell?

Let me preface this question by saying that I get the need for unit testing. I painfully get it. You have to do it to ensure that future modifications don't adversely affect the application in ways ...
3
votes
6answers
236 views

Unit Testing with an Optimization Problem

Suppose I'm making an algorithm that identifies the subject of a picture. It could be anything that a computer doesn't do that well, but I'm not expecting to get the right answer every time - 80% is ...
37
votes
9answers
4k views

Do we need Logging when doing TDD?

When doing the Red, Green & Refactor cycle we should always write the minimum code to pass the test. This is the way I have been taught about TDD and the way almost all books describe the process. ...
1
vote
3answers
171 views

C++ project organization to reduce unit testing build time

I want to organize tests for a project large enough that build time matters (especially for the CI server). Say I have this code that I would like to test : //foo/greet.cpp #include <stdio.h> ...
0
votes
1answer
153 views

Mixing declarative & imperative code (Implicit 'unit tests' ?) [closed]

Well I'm no expert, but as a student, I'm curious about languages and their design patterns / goals. I'd like to know, whether there are any points I miss in the following examples, and why ...
0
votes
1answer
166 views

What kind of a test is a “consistency check”?

Some or all of the tests I write and run are checks for consistency e.g. assert that if I create a new user account, that the account that was created actually has the same name as the name that was ...
4
votes
6answers
515 views

Are HSQLDB unit tests an anti pattern?

HSQLDB is great. It (also) has an embedded mode (no dedicated server needed), which allows for quick prototyping of stuff like Proof of Concepts, and it can also be great in production-ready ...
2
votes
1answer
262 views

equals and hashcode methods autogenerated, is it always a good practice?

Preamble: Let's say I aim to cover all my classes with test coverage. Despite the common opinion (expecially in Java community) to "not pay too much attention to Cyclomatic Complexity (CC) and code ...
62
votes
10answers
4k views

Does it make sense to write tests for legacy code when there is no time for a complete refactoring?

I usually try to follow the advice of the book Working Effectively with Legacy Code. I break dependencies, move parts of the code to @VisibleForTesting public static methods and to new classes to make ...
4
votes
8answers
358 views

How to measure that a team is doing Test Driven Development

My team is considering a department goal of doing Test Driven Development next (fiscal) year. TDD sounds good and my manager is on board. The only problem is measurement. Our company rules require ...
1
vote
5answers
373 views

Should unit-tests be entirely self-contained? [duplicate]

As the title suggests my question is whether or not unit-tests should be entirely self-contained or can one rely on the results yielded by previous tests? What I mean, in case that it isn't entirely ...
20
votes
7answers
785 views

Should I have unit tests for known defects?

If my code contains a known defect which should be fixed, but isn't yet, and won't be fixed for the current release, and might not be fixed in the forseeable future, should there be a failing unit ...
4
votes
2answers
150 views

Unit tests tactics

The only unit tests tactic I'm familiar with is comparing against golden data _ a predefined set of input data for which output is known (preferably including corner cases). I cannot think of any ...
1
vote
1answer
233 views

Unit testing methods with logical dependencies on other classes

Suppose I have an interface declaring the following method signature: SearchResults SearchProducts(string type, string filter, string anotherFilter); Inside a concrete implementation of this, I ...
1
vote
4answers
371 views

What are the valid test cases for method calls within if-else condition

I have a discount service that gets called if certain conditions are met. I need to write test cases to check if the discount service is called. My doubt is checking if the discount service is NOT ...
15
votes
8answers
767 views

What are good unit tests to cover the use case of rolling a die?

I'm trying to get to grips with unit testing. Say we have a die which can has a default number of sides equal to 6 (but can be 4, 5 sided etc.): import random class Die(): def __init__(self, ...
0
votes
0answers
72 views

Model Driven Design with Bean Validation

If I have a rich domain library that gets included into a Java web application, but I want to achieve a level of dependency isolation with that domain library such that it is possible to build and ...
0
votes
0answers
385 views

How to integrate unit testing process into legacy software development process? [duplicate]

I'd like you to share your insights of how have you successfully turned the direction of rotting legacy code base to modular application design where it's easy and useful to add unit tests? What I'm ...
0
votes
2answers
92 views

How should I test the functionality of a function that uses other functions in it? [duplicate]

Suppose there is a function get-data which returns a map of information about the id of the user passed in. now this function uses 3 functions source-a, source-b and source-c to get three different ...
10
votes
3answers
543 views

How do I stress the importance of unit tests to my manager [duplicate]

I've recently started a new job, & I've been tasked with completing a feature that another developer didn't finish before he left the company. The existing tests are out of date (i.e ...
11
votes
4answers
637 views

Is there a better way of writing unit tests than a series of 'AssertEquals'?

Here's a basic example of what my unit test needs to be, using qunit: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> ...
0
votes
2answers
218 views

How do I read the Entity Framework Model and validate it against a given connection?

I have a Entity Framework Database First Model. I want to write a MSTest/nUnit test to verify that all the stored procs, tables and views that are defined in my edmx model are still valid on the ...
0
votes
0answers
66 views

Unit Testing in iOS — Should I split out my Data Model into it's own class?

I'm attempting to try out using unit test in for the first time in new iOS activity for work. I love the idea of unit testing, but always find the specifics to be... messy. I get the general ...