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)

2
votes
1answer
81 views

Working with Dependency Injection using Factory pattern

I want to build a .jar that encapsulates a vendor api, so we can use our own objects as parameters to communicate with the api. I've read some articles and topics here in SO, but I still am a bit ...
-3
votes
0answers
36 views

Sample embedded projects with unit tests written [closed]

I have a question related to the following post: best practice when unit testing for embedded development I am looking for some sample projects (may be on github) that have unit tests enabled. See ...
1
vote
1answer
101 views

How would you test this class and is it integration test or unit test?

Consider this example class which in encrypting some data and sending it to some other service. Consider the test for redirect method. This is how you consume the class: <?php $safeLink = new ...
1
vote
1answer
68 views

How to test software with near-real-time requirements?

So, I've been refactoring my videoconferencing application for a while, covering it with unit and general tests. Finally, I got to the point where I need to write a loopback test with 1 client sending ...
80
votes
12answers
11k views

Would unit tests have helped Citigroup to avoid this expensive mistake?

I read about this snafu: Programming bug costs Citigroup $7m after legit transactions mistaken for test data for 15 years. When the system was introduced in the mid-1990s, the program code ...
1
vote
1answer
27 views

How perform automated tests over code that changes a DBMS (throught DML or DDL)?

I'm written a software as an exercise to improve my skills and I ask my self about how to test code that changes a database. Let the code in my github: https://github.com/daniloanp/Ensaios/blob/...
2
votes
1answer
47 views

Documentation for unit tests

I have a small project written primarily in C++ which is documented with Doxygen and tested with a unit testing framework (Google Test in my case, but that doesn't matter). I wrote several test cases ...
1
vote
1answer
125 views

Unit tests became unstable after upgrading compilers and IDEs

I have a set of about 300 unit tests that have been through a difficult few months. The poor tests were subject to being upgraded from a V110 compiler (Visual Studio 2008) alongside Visual Studio 2012 ...
1
vote
2answers
83 views

Is a unit test using setup code an integration test?

Programming books usually preach to only test a single method in a unit test. This is supposed to keep the tests independent of each other and reduce the amount of work needed to rewrite the tests if ...
0
votes
3answers
79 views

Choosing an epsilon when comparing floating point numbers across different systems

I am transcribing thousands of lines of computational code from MATLAB to C++. I don't fully understand the math myself, but I can run it with MATLAB, assume it's correct, and compare the results to ...
1
vote
1answer
45 views

Unit testing with external packages or assemblies

I'm unit testing a class which has two dependencies, both of which are external packages (I'm using C# so these are NuGet packages, AutoMapper and CompareNETObjects). (NOTE: Both are just utilities,...
3
votes
2answers
98 views

Diferences between Test vs Spec

I am having a concept problem at this point & I can't find any info about the differences between Test (UnitTest, etc) vs Spec (Rspec, etc). As far as I know, specs is into Integration tests and ...
0
votes
0answers
17 views

AutoFixture Problems with simple Types

I am trying to do TDD (I am a beginner in TDD) in my current project (WPF application, MVVM, C#) and use following frameworks for my tests: NUnit AutoFixture I have a ViewModel-class that I want ...
4
votes
3answers
137 views

How would one test a function with a large number of scenarios?

I've heard that it's ideal to have one assert (or expect or should, etc) per aspect of a component's behavior you're trying to test. Is this how it works? An addOne function would be tested like this, ...
0
votes
0answers
26 views

creating a teartown in integration test by deleting the test database and load the mdf again

I had a Friday developers debate with all my smart colleagues about Tear down process in Integration testing. They are putting a debate that getting a new database mdf file is better while during ...
67
votes
10answers
6k views

Where is the line between unit testing application logic and distrusting language constructs?

Consider a function like this: function savePeople(dataStore, people) { people.forEach(person => dataStore.savePerson(person)); } It might be used like this: myDataStore = new Store('some ...
50
votes
11answers
8k views

Are magic numbers acceptable in unit tests if the numbers don't mean anything?

In my unit tests, I often throw arbitrary values at my code to see what it does. For example, if I know that foo(1, 2, 3) is supposed to return 17, I might write this: assertEqual(foo(1, 2, 3), 17) ...
4
votes
2answers
165 views

How am I supposed to add tests for all my projects?

I have been teaching myself how to code for about a year (I'm 17) and one of the most common things that I've come across while reading articles about programming is automated tests for your code. I ...
0
votes
0answers
24 views

Do you inject everything explicitly used in a module even if it is loaded in a “parent” module?

When you build a app modularized what do you inject into submodules? Only those things that are used there but not added at the top level, or do you inject everything that is explicitly used in that ...
2
votes
2answers
126 views

Unit testing / How to validate private fields of a newly created object?

I have a basic unit test (for the sample) that involves this code: void testShouldCreateACar() { Car car = someone.createFerrari(); assertTrue(car.name == "Ferrari"); // can't access name since ...
115
votes
12answers
12k views

Time difference between developing with unit tests vs no tests

I'm a solo developer with a pretty time-constrained work environment where development time ranges usually from 1-4 weeks per project, depending on either requirements, urgency, or both. At any given ...
0
votes
0answers
32 views

Debugger directions

I am running an old DOS executable file that runs a set of instructions to test an electronic component via com1 (RS-232) on a pc. The 16bit software has 8 main routines and some subroutines within to ...
1
vote
1answer
100 views

How to refer to unit tests not cleaning up after themselves? [closed]

I am looking for a concise way to refer to the phenomenon of a unit test failing to clean up one or more artifacts, which affects the behavior/outcome of subsequent tests. Is there a standard term ...
-1
votes
0answers
40 views

What to do to during unit testing [duplicate]

I have trouble understanding what to do when unit testing. All over the web I find tutorial for how to use unit testing but it is always just tutorials about how the unit testing tools are working but ...
26
votes
3answers
3k views

Are integration tests meant to repeat all unit tests?

Let's say I have a function (written in Ruby, but should be understandable by everyone): def am_I_old_enough?(name = 'filip') person = Person::API.new(name) if person.male? return person....
27
votes
8answers
4k views

Value of using private methods vs all public in classes for internal software for ease of unit testing [duplicate]

Here's a skeleton of a class I built that loops through and deduplicates data - it's in C# but the principles of the question aren't language specific. public static void DedupeFile(FileContents fc) {...
9
votes
4answers
506 views

Dependency Inversion expands the API, results in unnecessary tests

This question has bothered me for a few days, and it feels like several practices contradict each other. Example Iteration 1 public class FooDao : IFooDao { private IFooConnection fooConnection;...
8
votes
2answers
747 views

Why aren't all method virtual or why doesn't have each class at least one interface?

This is more philosophical question, which address .NET platform, but maybe it is useful also for other languages. I'm doing lot of Unit Testing and especially when I'm using third-party components I ...
18
votes
5answers
650 views

Agile without unit tests

Does it make sense to talk about "agile development" or claiming that you are applying an "agile methodology" if the code base you are working on has 0% unit test coverage? (And you, as a team, are ...
1
vote
1answer
65 views

Spring - rest API - How to unit test a rest API which gets data from another service

I am new to rest API's as well as mocks. Please help me .. I have a set of rest API's for which I need to write unit tests. rest API in turn calls another service , gets the JSON response and sends ...
4
votes
4answers
397 views

Are there any alternatives to dependency injection for stateless classes?

I am working on an application whereby I have designed classes to fit into several groups: Immutable: initialised through constructors, uses copy-and-swap idiom (inc. move), can deep copy (i.e. ...
26
votes
6answers
2k views

Is there any point in unit testing a client service that simply passes through data from the server? [duplicate]

Imagine a simple AngularJS REST Service which retrieves (GET) data from REST endpoints on a server. It maintains no state of its own and each method only passes back a promise to whomever is using ...
20
votes
6answers
2k views

How to remove a function or feature when using TDD

In texts about TDD I often read about "remove duplication" or "improve readability" during the refactoring step. But what makes me remove an unused function? For example let's say there is a class C ...
4
votes
2answers
34 views

Test arrangement using the system under test

I have some integration tests around stored procs. Typically I do the test setup using Dapper. This is fine for simple cases, but in some cases to setup up the system correctly it would be far simpler ...
13
votes
2answers
1k views

How to go about testing un-injectable code?

So I have the following piece of code in use all over my system. We're currently writing unit tests retrospectively (better late than never was my argument), but I don't see how this would be testable?...
53
votes
9answers
6k views

How to write unit tests before refactoring?

I've read some answers to questions along a similar line such as "How do you keep your unit tests working when refactoring?". In my case the scenario is slightly different in that I've been given a ...
2
votes
4answers
155 views

Unit Test for Void which copies data from one location to another

Still learning and getting my head around Unit Testing, (also trying to get into TDD, though I appreciate it isn't the same thing) and in many ways it is changing/improving my code. But I come across ...
4
votes
1answer
133 views

Have the unit test “using” the project, or just have same namespace?

Background I am working on a project with C# .NET, and I've just added a new unit test project to my solution in Visual Studio. The way that I always have been doing this is: Create a new unit test ...
13
votes
2answers
670 views

Where to push a failing test?

I just changed branch settings on my GitHub repository, so that my [next] branch requires a passing CI build through a pull request. A discussion followed with a number of team members, about failing ...
0
votes
0answers
23 views

Making my dependencies available in my public interfaces

I've made a bute Visual Studio extension. It works, and now I want to make it extensible and add unit tests. I notice straight off that I'm passing around within my methods, and making available in my ...
24
votes
8answers
4k views

Wouldn't it be beneficial to write tests during code review?

A colleague of mine came up with an idea that I found interesting. Wouldn't it be beneficial to write tests during code review, by the person doing the review assuming that we don't do TDD? For ...
33
votes
6answers
3k views

Should there be unit tests for complex regular expressions?

Should I write unit tests for complex regular expressions in my application? On the one hand: they are easy to test because input and output format is often simple and well-defined, and they can ...
1
vote
1answer
161 views

Unit testing C code?

I learnt about the check testing framework today that seems good. This far I've scripted tests that uses valgrind so that the tests both display output from the tests and from valgrind. Is there a ...
1
vote
0answers
77 views

How to get verification that you've implemented all your API in a static library?

I just learned that static library building skips the linking stage, which explains why my build process succeeds all the time when it's possible I actually haven't implemented a function in my header....
2
votes
3answers
93 views

Testing properties with private setters

Currently in a part of my project a domain object like below exists: public class Address { public virtual string HouseName { get; set; } public virtual string HouseNumber { get; set; } ...
0
votes
0answers
39 views

How to understand code of Rails app written by other devs and test it accordingly?

Rails beginner here with less than year experience in programming.I have some experience writing trivial Rails apps (with CRUD implementation like simple blog) and I have some knowledge how to write ...
2
votes
1answer
59 views

Writing Automated test cases for a folder Archiving Class.

Using C# and Visual Studio, I've developed a class that zips and archives a folder into desired location, creating directories and manipulating files on a machine. The intended use is as an part of ...
3
votes
2answers
164 views

Write unit tests for the libraries, or just the application?

Background I am fairly new to unit testing, and have been recently using the Visual Studio Test Manager to create my Unit Tests. The way that I have currently been doing things is as follows: ...
5
votes
3answers
188 views

Should unit tests always overlap

This is a test design question. I have a class 'handler' that accepts a 'validator' that checks some business logic on what's passed to the handler. I made the unit tests for the validator and now I'...
2
votes
2answers
137 views

Method to validate an object - should I have one method encapsulating all validation logic

I have a class, Customer which has some basic properties on it such as firstname, surname, email, dateofbirth. I have written another class called CustomerValidation which currently has one public ...