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)

10
votes
5answers
3k views

End-to-end tests versus unit tests, should tests be decoupled?

At our company we typically make sure that we write an end-to-end test for our websites/web apps. That means we access a URL, fill in a form, submit the form to another URL and check the results of ...
3
votes
2answers
355 views

Should an integration test be used in place of a unit test involving personal data?

I am trying to develop a series of unit tests for a production system that are dependent on a person's social security number. While I am more than comfortable hard coding a clearly bad social ...
0
votes
2answers
525 views

when to mock in unit testing [duplicate]

I am trying to write unit tests in javascript for an application made in nodejs. What I want to know is - Say there is a class Vehicles which is dependent on another class Roads. Should I mock the ...
15
votes
5answers
969 views

Is this pattern bad? [duplicate]

I notice that when I code I often use a pattern that calls a class method and that method will call a number of private functions in the same class to do the work. The private functions do one thing ...
25
votes
4answers
4k views

Is there a point to unit tests that stub and mock everything public?

When doing unit tests the "proper" way, i.e. stubbing every public call and return preset values or mocks, I feel like I'm not actually testing anything. I'm literally looking at my code and creating ...
3
votes
4answers
603 views

Initializing derived classes in the same way

I have a class Base that has several children, say A, B, C. For testing purposes I'd like to mock those derived classes by deriving from them. So MockA derives from A, MockB derives from B and so on. ...
1
vote
3answers
122 views

How should test for a “for any different than x return false” requirement look like

I tried to find if there's a similar question but didn't even know what keywords should I use :) I got a method in an interface accepting an other interface as a parameter: bool CanDoIt(AnInterface ...
1
vote
0answers
117 views

Unit Tests for Database Abstraction Layer

I previously asked this question about creating an algorithm for joining records from multiple databases, and since then, I have built a rudimentary version of it (which doesn't allow for inter ...
1
vote
2answers
410 views

Fundamental TDD: stuck with writing a test so I can write code that I want

I have a Season class. This Season has a few properties: among them, a list of Games. This should be populated from the same source that populated the rest of the Season properties. I have a test ...
3
votes
1answer
183 views

Shared context: good or bad?

RSpec allows users to share context across tests / examples, which would reduce the number of code lines in my app by a significant amount. On the other hand, somehow related to the question of ...
5
votes
3answers
484 views

Time consuming Unit test for support for 100,000 records: Am I doing it right?

I am working on adding test coverage for an application that previously didn't have any. One additional requirement that emerged is that one of the background processes should be able to process ...
3
votes
7answers
713 views

Why don't I see many unit test projects that bring up and tear down a DB? (ASP.NET MVC)

I see all the examples that demonstrate unit testing code and mocking the calls to the DB since you are not suppose to touch the DB. But it seems to me having a set up tasks that uses the actually ...
9
votes
2answers
2k views

How to unit test method that returns a collection while avoiding logic in the test

I am test-driving a method that is to generate a collection of data objects. I want to verify that the properties of the objects are being set correctly. Some of the properties will be set to the same ...
4
votes
5answers
865 views

How can I test parts of my application against the output of third party application?

I have a fairly new C# application, approximately 6 months old, that we are now trying to incorporate testing into. (Should have been done from the start but I can't change the past) Parts of this ...
4
votes
1answer
403 views

How to keep unit tests independent?

I've read it at many places that unit tests should be independent. In my case I have a class that does data transformation. These steps must be done sequentially, otherwise they don't make sense. For ...
1
vote
2answers
315 views

How do you test database abstraction in PHP?

I apologise in advance if this question is too subjective but I'm struggling to find a good answer, probably as there is not really a correct answer to give. I'm currently writing a database ...
8
votes
3answers
750 views

What would help when refactoring a large method to ensure that I don't break anything?

I'm currently refactoring a part of a large codebase with no unit tests whatsoever. I tried to refactor code the brute way, i.e. by trying to guess what the code is doing and what changes wouldn't ...
4
votes
2answers
429 views

What is the most appropriate testing method in this scenario?

I'm writing some Objective-C apps (for OS X/iOS) and I'm currently implementing a service to be shared across them. The service is intended to be fairly self-contained. For the current functionality ...
1
vote
4answers
521 views

Unit Test code generation

We have a project that was written over a period of 2 years, but has a poorly designed architecture and not unit tests. The software works well, but we're at the point where we want to refactor some ...
2
votes
1answer
348 views

Why do we write our specs in different files from our source?

The D Programming Language supports writing unit tests inline with source. There's a Ruby gem called test_inline that lets you write specs in the same file as your code. Why is it generally ...
4
votes
2answers
453 views

Testcase runner for parametrized testcases

Let me explain my situation. I'm planning a kind of test case runner for doing testcases on external devices, which are microcontroller based. Lets consider the devices: Device 1 Device 2 There ...
3
votes
4answers
985 views

How to determine most challenging test-cases to test any algorithm?

While solving any problem, we write algorithms. Some efficient, some not, some work, some fail. But sometimes we end up writing something which is mostly a success when we do a dry test run, perhaps, ...
3
votes
1answer
137 views

Unit Testing and “Fit”

I am reading Cristopher Alexander's "Notes on the Synthesis of Form", and he is describing a solution to a problem as having good fit, when there is an absence of bad fit; we can't describe all of the ...
1
vote
3answers
440 views

If functional testing is referred as black box..how can it be done on unit test level?

Preparing myself for ISTQB, I found a bit odd many things in their textbooks. E.g. they call black box testing as functional testing when you are not concerned with structured but only observe the ...
9
votes
4answers
1k views

In Unit Testing, why would I create a Repository twice?

The other day I was reading a little about Unit Testing and I saw some examples where people create a repository interface (i.e. IExampleRepository) and then create the real repository (public class ...
1
vote
1answer
977 views

How to write unit tests without mocking data

My design doesn't allow me to mock the data so I am using sqlite as test database that has minimum data to run the unit tests. Below is the pseudo code //Method to be tested public IList<Funds> ...
2
votes
2answers
301 views

How to unit test code which is intended to have different results on different platforms

I noticed some duplicate code in a codebase I am working on that appended a filename to a directory path, so I decided to refactor it into its own method. The application I am working on is not well ...
1
vote
3answers
565 views

Unit-testing functions without business logic (only checks) [duplicate]

My team is trying to find out the best way to test one of our components; the main scope is to check if the user/actor has the right to complete the operation requested. The component is formed by ...
4
votes
5answers
5k views

Understanding unit tests/TDD for ASP.NET webforms [closed]

I'm the lead programmer at a small software firm (currently 4 developers including myself), we develop bespoke ASP.NET WebForms applications for businesses. I joined there in 2010 just after ...
7
votes
1answer
9k views

How can I unit-test my REST web service?

I am new to unit testing, I've one REST web method that just calls DB and populates a DTO. Pseudo code is public object GetCustomer(int id) { CustomerDTO objCust = //get from DB return objCust; } ...
2
votes
5answers
572 views

Unit test cases(JUnit), not by developer but other team members

I have a very interesting situation. Management has strictly asked to do unit testing for the code being developed and divided the task in such a way that few are developing the code and others are ...
2
votes
1answer
839 views

JUnitEE vs JUnit

I know what unit testing is in general and what JUnit is in particular. But here I see that there is a project called JUnitEE which seems to me to be a wrapper over JUnit. So I would like to better ...
8
votes
4answers
960 views

In TDD, if I write a test case that passes without modifying production code, what does that mean?

These are Robert C. Martin's rules for TDD: You are not allowed to write any production code unless it is to make a failing unit test pass. You are not allowed to write any more of a unit test than ...
1
vote
3answers
160 views

What should a test method test? [closed]

Suppose we're unit testing a class with xUnit-like framework - so a test class is created for class-under-test. Now, how much should be tested by individual test methods? Should there be one-to-one ...
19
votes
5answers
3k views

Unit Testing in a “no setter” world

I do not consider myself a DDD expert but, as a solution architect, do try to apply best practices whenever possible. I know there is a lot of discussion around the pro's and con's of the no (public) ...
0
votes
2answers
511 views

Should I use TDD and BDD if my project is changing fast?

I have my own little project I am creating using RoR, I plan it to have small-medium load. With no doubt I started with BDD and TDD (Cucumber and RSpec to be exact, but I am also experienced with ...
19
votes
3answers
6k views

Is there any real value in unit testing a controller in ASP.NET MVC?

I hope this question gives some interesting answers because it's one that's bugged me for a while. Is there any real value in unit testing a controller in ASP.NET MVC? What I mean by that is, most ...
2
votes
4answers
267 views

How do I test my validation without being too much perfectionist, yet to leave most part of logic tested?

For example I would like to validate that name is letters only and is between 4 and 14 letters length. I have the following code in model: validates: name, :format => { :with => /^[a-zA-Z]+$/, ...
12
votes
1answer
890 views

Is there a modern replacement for a mutation testing tool like Jester for Java?

“Why just think your tests are good when you can know for sure? Sometimes Jester tells me my tests are airtight, but sometimes the changes it finds come as a bolt out of the blue. Highly ...
3
votes
2answers
227 views

Do I need to learn python first to understand the part 2 of the book Test Driven development?

It seems like Python is used as a coding language for part 2 of Kent Beck's book Test Driven Development. I have read the first part of that book and started appreciating the value of TDD . First part ...
9
votes
6answers
4k views

Testing a REST client against a REST Server. How to do fixtures?

When writing unit tests, it's common to use fixtures: little testable data, so we can say: 1. Get all clients should include Willy Wonka. 2. Delete client 3, and now get clients should not include ...
16
votes
3answers
1k views

Brittle unit tests due to need for excessive mocking

I've been struggling with an increasingly annoying problem regarding our unit tests that we are implementing in my team. We are attempting to add unit tests into legacy code that wasn't well designed ...
2
votes
2answers
281 views

Building automated unit tests for tools which don't have an xUnit implementation

Preamble I have been bitten by the bug of automated unit testing. I feel the benefits and the confidence in a code base it can deliver. I am also feel I have a reasonable intuition as to what parts ...
9
votes
1answer
579 views

Unit testing in Django

I'm really struggling to write effective unit tests for a large Django project. I have reasonably good test coverage, but I've come to realize that the tests I've been writing are definitely ...
2
votes
2answers
281 views

Mock up class object

For example I have class ItemDownloader which has method downloadItem. This method creates instance of another class - Download to perform actual downloading. Question is: I want to test ...
4
votes
3answers
791 views

How to invoke anonymous functions in testing?

Below is Java code. I need to cover the below function. I searched for many websites, but I still have no ideas. Is there any methods to cover the override anonymous classes? public static void ...
8
votes
1answer
1k views

Unit testing on visualization (3D graphics) frameworks

This is a follow up to this question. There I was asking how to do unit testing when you have a library of scientific algorithms. I have a similar problem now but with a different project. I'm ...
12
votes
3answers
23k views

Best way to unit test methods that call other methods inside same class

I was recently discussing with some friends which of the following 2 methods is best to stub return results or calls to methods inside same class from methods inside same class. This is a very ...
7
votes
1answer
408 views

Unit testing for a scientific computing library

I've had a bit of experience with unit testing before, in what I call (not pejoratively) the classic software engineering project: an MVC, with a user GUI, a database, business logic in the middle ...
69
votes
11answers
6k views

Is there a reason that tests aren't written inline with the code that they test?

I've been reading a bit about Literate Programming recently, and it got me thinking... Well-written tests, especially BDD-style specs can do a better job at explaining what code does than prose does, ...