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
5answers
198 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 ...
0
votes
2answers
3k views

Should I use a separate class per test?

Taking the following simple method, how would you suggest I write a unit test for it (I am using MSTest however concepts are similar in other tools). public void MyMethod(MyObject myObj, bool ...
3
votes
1answer
46 views

Testing a class with “prerequisite” methods

I'm working on a class that should manipulate files. Its interface has a Open(string filename) method, and various other methods to retrieve and manipulate the contents. Is it ok to call the open ...
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 ...
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
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
70 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 ...
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, ...
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 ...
21
votes
3answers
8k 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?
31
votes
7answers
14k views

best practice when unit testing for embedded development

I am looking for some best practice strategies for unit testing code written for embedded system. By embedded system, I mean code such as device drivers, ISR handlers etc., stuff that are pretty close ...
1
vote
1answer
127 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
84 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 ...
1
vote
1answer
1k views

How to test model binding within an MVC controller when Bind attribute with Include list is used?

Auto-generated action methods in MVC5 make use of the BindAttribute with an Include list that contains the field names in a string literal. Example: // POST: MyTable/Edit/5 // To protect from ...
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
3answers
80 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,...
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
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 ...
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 ...
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 ...
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) ...
5
votes
3answers
372 views

How important is automated testing in rapid release, non-critical (web) apps?

I think I understand the theoretical benefits of automated testing, especially unit testing. However, I'm not sure what the optimal amount of testing is when the project is a non-critical, rapidly ...
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 ...
4
votes
4answers
403 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. ...
4
votes
8answers
545 views

Testing loses its effectiveness if all programmers don't use them

Let's assume you are convinced that the extra time spent unit testing has merit and improves production. Does that still hold up when everyone working on the same code doesn't use them? This question ...
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 ...
72
votes
10answers
8k views

Are (database) integration tests bad?

Some people maintain that integration tests are all kinds of bad and wrong - everything must be unit-tested, which means you have to mock dependencies; an option which, for various reasons, I'm not ...
2
votes
2answers
127 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 ...
4
votes
2answers
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 ...
7
votes
3answers
3k 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
2answers
614 views

Who should initialize dependencies in a TDD application?

I'm trying to learn implementing TDD with mocking/fake objects. One of the questions I have is how to initialize a dependency in an application which implements TDD? An example from this article ...
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 ...
194
votes
13answers
98k views

Is it OK to have multiple asserts in a single unit test?

In the comment to this great post, Roy Osherove mentioned the OAPT project that is designed to run each assert in a single test. The following is written on the project's home page: Proper unit ...
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) {...
-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 ...
9
votes
1answer
178 views

Unit testing for data munging pipelines made up of one-line functions

Reading Mary Rose Cook's Practical Introduction to Functional Programming, she give as an example of an anti-pattern def format_bands(bands): for band in bands: band['country'] = 'Canada' ...
18
votes
5answers
654 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 ...
14
votes
3answers
5k views

Is it actually worth unit-testing an API client?

This is something that's been troubling me for a while now. Is it actually worth unit-testing an API client? Let's say you're creating a small class to abstract-away the calls to a petshop REST API. ...
9
votes
4answers
507 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;...
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 ...
8
votes
2answers
748 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 ...
1
vote
1answer
69 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 ...
3
votes
1answer
123 views

How to move Python doctest examples into another unit test framework?

Years ago AFAIK the mathematitician and software developer Tim Peters discovered that very often the documentation of APIs tends to get out of date over time during the software live cycle, because ...
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 ...