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)

3
votes
2answers
351 views

Advise how to write a simple test for this javascript snippet?

I'm trying to start unit testing (not using any testing frameworks) for my javascripts. Here's one example of it. var obj = {}; obj.disableBtn = function ($btn, style) { ...
0
votes
1answer
211 views

Method visibility for testing partial mocks

I'm currently writing unit tests to test behavior of a method and would like to partially mock the methods calling injected properties. For example: public void doSomething() { int complicatedInt ...
4
votes
1answer
801 views

What to test when building websites using CMS?

My job is mainly building websites using CMS such as Drupal, eZPublish or Magento. Most of the work is templating, CRUD and adhering to the specs with this. Occasionally, there is some ...
51
votes
7answers
5k views

Writing Tests for Existing Code

Suppose one had a relatively large program (say 900k SLOC in C#), all commented/documented thoroughly, well organized and working well. The entire code base was written by a single senior developer ...
2
votes
2answers
676 views

Should I bother to write unit test for UI/UX Components?

So I am building an application with Angular and have started to get into UI testing with DalekJS (http://dalekjs.com). As I have been writing these tests I have been thinking to myself, should I ...
2
votes
2answers
571 views

Unit Tests work but there are still bugs?

Brief History I am new to Automated Unit Testing and Mocking objects world; previously we used to do Unit Testing (including Integration Testing and we mistakenly referred that as Unit Testing) ...
15
votes
6answers
5k views

Unit-Tests and databases: At which point do I actually connect to the database?

There are answers to the question on how test classes that connect to a database, e.g. "Should service test classes connect ..." and "Unit testing - Database coupled app". So, in short let's assume ...
2
votes
2answers
416 views

Unit testing and coupling

As a developer I should strive for low coupling between classes. But low coupling doesn't mean "No coupling" so sometimes I have to allow some code flexibility and use "new" inside a domain model. ...
6
votes
4answers
647 views

I have 200k lines of poorly designed code, will units tests or integration tests be more valuable? [duplicate]

I've inherited a lot of poorly designed code; the code has no tests. I am putting tests in place before I attempt a major refactor, but I have run into a problem with my unit tests. The problem is, I ...
3
votes
2answers
186 views

Unit test strategy for layered (or derived) method calls

Forgive the title -- it needs work. I am struggling to find better English to express my issue. Edits encouraged. Example to describe my issue: Checker Method I have an argument checking method ...
0
votes
2answers
767 views

Unit testing in node.js and mocking modules

I'm trying to test this wrapper to request that I made: // lib/http-client.js var app = require('app'), request = require('request'); exports.search = function(searchTerm, next) { var options ...
1
vote
3answers
390 views

Does non-virtual-by-default lead us to composition-over-inheritance?

There are some design guidelines about testable code in “The Art of Unit Testing”. The first one is “Make methods virtual by default”. I’m curious to know your idea about non-virtual-by-default ...
2
votes
1answer
266 views

TDD / one test representing the whole scenario ? or should I split it? [duplicate]

While practicing TDD, I came across this specification: A user should be created with its password hashed, be persisted and an activation token should be returned. Should my first unit test, (aiming ...
3
votes
1answer
2k views

Should we mock entities and value objects when doing DDD?

After reading a few articles about Newable vs Injectable objects and how these concepts relate to DDD's services, entities and value objects, I was left with some doubts about using newables in my ...
0
votes
1answer
558 views

Is it worth writing a unit test for a DTO with the most basic getter/setters? [duplicate]

The advantage is it protects your DTO against future "enhancements" ?
13
votes
5answers
2k views

Do I need unit test if I already have integration test?

If I already have integration test for my program, and they all passed, then I have a good feel that it will work. Then what are the reasons to write/add unit tests? Since I already have to write ...
1
vote
3answers
256 views

Unit Test - an Enigma? [duplicate]

I am an objective-c/iOS apps developer and I was wondering if I perform Unit Tests on my code, how should I go about it? What is unit test anyway? Ain't I testing a specific part of code while ...
2
votes
6answers
409 views

How to write unit tests for utility programs

I am working on a C# console application that loads the data from a third party and bulk inserts into tables. Basically the code consists of a static method with logging statements. In these ...
49
votes
6answers
4k views

65.000.000.000 tests to run

I was asked about how to run a suite of 65.000.000.000 tests and I wonder if it is normal to have a project with such a huge amount of tests. Have you worked in projects with this characteristic?
5
votes
2answers
481 views

Tools that can catch “fake coverage”?

Hypothetical scenario: codebase is exercised by unit tests run by a TeamCity build-bot, that also uses the built-in dotCover tool to provide coverage metrics. The build will fail if less than X% of ...
3
votes
1answer
293 views

calling test methods within other test methods

To test a method that returns a clone of the object it is called on, i need to re-run the test suite on the newly created object if i am to ensure that full functionality is retained, i found my ...
1
vote
4answers
249 views

Writing unit test only for applications that requires them [closed]

Bit of a rant, but bear with me. People call me purist. I do not code in any way other than TDD. When I try to push TDD as a company policy, the following conversation: company owner: "we'll do TDD ...
7
votes
3answers
842 views

TDD Mock call verification - is it an anti-pattern?

I've been doing TDD for year now, I feel pretty good about it, I love my test suites and all. However I've noticed that lately I've been doing a lot of mock call verification. For example I'd have a ...
2
votes
2answers
282 views

unit testing variable state explicit tests in dynamically typed languages

I have heard that a desirable quality of unit tests is that they test for each scenario independently. I realised whilst writing tests today that when you compare a variable with another value in a ...
6
votes
2answers
770 views

Unit test SHA256 wrapper queries

I have the following SHA256 wrapper. public static string SHA256(string plainText) { StringBuilder sb = new StringBuilder(); SHA256CryptoServiceProvider provider = new ...
2
votes
2answers
3k views

Need help understanding Mocks and Stubs

I'm new to use mocking frameworks and I have a few questions on the things that I am not clear on. I'm using Rhinomocks to generate mock objects in my unit tests. I understand that mocks can be ...
2
votes
2answers
780 views

CppUnit for unit-testing executable files?

I am not sure if anyone has done it. I am trying to do something that is in general, uncommon i.e. unit-testing executable (Windows) or ELFs (Linux). I know that CppUnit provides a good unit testing ...
1
vote
1answer
115 views

How can I test linkable/executable files that require re-hosting or retargeting?

Due to data protection, I cannot discuss fine details of the work itself so apologies PROBLEM CASE Sometimes my software projects require merging/integration with third party (customer or other ...
10
votes
10answers
1k views

Any tools/suggestions on how to refute code coverage quality argument

Now I know people could consider this question duplicate or asked many times, in which case I would appreciate a link to relevant questions with answer to my question. I have been recently in ...
25
votes
7answers
2k views

Should I be worried about overengineering programming assignments given during interview process? [closed]

I recently had a phone interview with a company. After that phone interview, I was told to complete a short programming assignment (a small program; shouldn't take more than three hours). I'm only ...
1
vote
4answers
2k views

Unit-Testing functions which have parameters of classes where source code is not accessible

Relating to this question, I have another question regarding unit testing functions in the utility classes: Assume you have function signatures like this: public function void ...
3
votes
5answers
302 views

Testing From A Developer's Perspective [closed]

I have a book which mentions: "There are many types of testing, including unit testing, integration testing, functional testing, system testing, performance testing, and acceptance testing". It ...
2
votes
1answer
156 views

Testing MVC models when using SQL referential constraints

I have an MVC web app that's wired against PostgreSQL. The DB uses the full gamut of various referential constraints to ensure referential integrity, as opposed to say the Rails approach, where you ...
-4
votes
7answers
2k views

Unit Test OR Console Application [closed]

I am to write some one-off code in c#.net that will do some db manipulation of existing records and call a third party REST Api to update those records. I proposed writing a unit test that does it. ...
1
vote
1answer
344 views

How to unit test a class which is just an adapter that logs input and output to a third-party library?

I have the following (in C#, but the question could also apply to Java): public interface ILibraryAdapter { string Property1 { get; } string Method1(string param1); ... } public class ...
2
votes
2answers
268 views

Unit tests and language-native function calls

Is there a best practice for calling language-native functions when writing testable code? I have experimented a little with php code and have come up with two methodologies: create a wrapper class ...
0
votes
1answer
152 views

How do you distinguish your public API interfaces from the interfaces you use for testing/mocking?

Mocking frameworks are useful for creating mock objects that isolate the code under test from its surrounding software environment. Some mocking frameworks cannot mock non-virtual methods, so they ...
0
votes
2answers
227 views

Should I make a seperate unit test for a method, if it only modifies the parent state?

Should classes, that modify the state of the parent class, but not itself, be unit tested separately? And by separately, I mean putting the test in the corresponding unit test class, that tests that ...
0
votes
3answers
218 views

What concept am I missing with private methods and testing? [duplicate]

I've read a lot o blogs arguing about private methods and testing. Some people say you should not test private methods, they say you should make them public or put those methods in a new class. But ...
57
votes
11answers
7k views

Is it a bad practice to modify code strictly for testing purposes

I have a debate with a programmer colleague about whether it is a good or bad practice to modify a working piece of code only to make it testable (via unit tests for example). My opinion is that it ...
11
votes
5answers
4k 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
394 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
633 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
991 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 ...
29
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
645 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
119 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
427 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
188 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 ...