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
3answers
152 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. ...
2
votes
2answers
57 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; } ...
22
votes
6answers
1k views

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

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
24 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 ...
51
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 ...
1
vote
1answer
145 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
4answers
9k views

How to Console.WriteLine from [TestMethod]?

I am trying to show some information from a [TestMethod] method. Usually we use NUnit and a line with Console.WriteLine runs fine and we can see it in 'output' window, but on this project we must to ...
2
votes
4answers
145 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
114 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 ...
11
votes
2answers
631 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 ...
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 ...
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 ...
-1
votes
0answers
60 views

Help defining code quality processes

Title says it all; we're a fairly young development team and all members have recently assigned accountability roles covering different areas of our software development process. I've been put in ...
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 ...
78
votes
12answers
7k 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, ...
7
votes
3answers
2k views

Never written much unit tests, how can I practice more of it?

I have an interview coming up soon next week and there's a few things on their list of responsibilties for this software development job (the job position title is vague, it says java developer) that ...
10
votes
5answers
22k views

How do you write unit test cases?

Sometimes I end up writing unit test cases for the code other developers have written .There are occasions when I really didn't know what the developer was trying to do (the business part) and just ...
1
vote
1answer
907 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 ...
8
votes
5answers
3k views

Test Driven Development: A good/accepted way to test file system operations?

I am working on a project at the moment that generates a table (among other things) based on the contents of a file-system, and in turn does some meta-data modifications on the things it finds. The ...
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 ...
1
vote
0answers
54 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 ...
69
votes
10answers
7k 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 ...
0
votes
0answers
35 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
53 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 ...
-2
votes
1answer
87 views

Test Cases in an Interview Setting

In the first cracking the coding interview video Ms. McDowell talks about candidates that begin by writing test cases in whiteboard interviews. How would one go about this? For example, the ...
2
votes
2answers
79 views

Is it possible to capture java objects to save them as test resources?

I'm wanting to write unit tests to check that for given database responses, certain objects are create/things are done. The problem I have, is that when mocking the database response, I have to ...
3
votes
2answers
158 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
175 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 ...
14
votes
3answers
267 views

Duplicating constants between tests and production code?

Is it good or bad to duplicate data between tests and real code? For example, suppose I have a Python class FooSaver that saves files with particular names to a given directory: class ...
2
votes
2answers
122 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 ...
3
votes
3answers
127 views

How to test data based on SQL queries?

I'm trying to set up a test framework for (SQL) datasets that get updated daily. I want to write assertions that involve comparisons between two tables–for example, the sum of column visitors in the ...
12
votes
4answers
1k views

This way I'm writing this code is testable, but is there something wrong with it I'm missing?

I have an interface called IContext. For the purposes of this it doesn't really matter what's it does except the following: T GetService<T>(); What this method does is look at the current DI ...
30
votes
2answers
2k views

How have Guava unit tests been generated automatically?

Guava has unit test cases automatically generated: Guava has staggering numbers of unit tests: as of July 2012, the guava-tests package includes over 286,000 individual test cases. Most of ...
2
votes
2answers
129 views

How to write unit tests for network client?

I need to write simple http client. It could be great to have unit tests for my class. But I don't know how to write proper and testable class. For example, I have a client like this: class ...
2
votes
3answers
155 views

When to mark a function as virtual?

I'm trying to understand the idiomatic way to code. I'm using gmock to unit test the components I write. Gmock requires methods to be virtual to be able to mock but the class I'm trying to mock has a ...
4
votes
1answer
162 views

Writing a valid test case for validating XMLs

How would I write a unit test, say JUnit, for validating an XML file? I have an application that creates a document as an XML file. In order to validate this XML structure, do I need to create an XML ...
0
votes
3answers
93 views

Determining the optimal amount of unit tests?

I think I may be writing -too- many unit tests. For example, say I was doing a coursework management system, and I coded a feature for submitting coursework on behalf of a student. If invalid ...
1
vote
2answers
95 views

Tests coverity and reusability problem

I am not very good at writing unit tests so I have a dilemma. I have a binary_search_tree and I am writing tests for insert and contains methods: struct BinarySearchTree {}; TEST(BinarySearchTree, ...
1
vote
4answers
127 views

How and where to test if the JSON request objects generated by the front-end is valid

We have built a complex Angular application that sends multiple HTTP request to a REST service that is also built in house. Since both the frontend and the backend is being developed in parallel, ...
0
votes
3answers
124 views

How to write testcases for a piece of logic? [closed]

I want to learn how to write testcases for a piece of logic like unit tests. Now I am not concerned about any specific framework or language, just wanted to know how can I get learn to write ...
30
votes
11answers
3k views

Writing the minimum code to pass a unit test - without cheating!

When doing TDD and writing a unit test, how does one resist the urge to "cheat" when writing the first iteration of "implementation" code that you're testing? For example: Let's I need to calculate ...
12
votes
3answers
675 views

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

I've recently started a new job and 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 useless)... ...
2
votes
1answer
137 views

Unit test express controllers?

I'm using meanjs for a project. It includes a yeoman generator with some express tests (model.test.js & routes.test.js) The tests do exactly what they advertise. My question is though, should I ...
1
vote
5answers
3k views

Should each method have a seperate JUnit test class?

I am writing JUnit unit tests for my classes. Is it better to have a separate class for each method, or have just one test class for every actual class?
4
votes
6answers
719 views

How does TDD address interaction between objects?

TDD proponents claim that it results in better design and decoupled objects. I can understand that writing tests first enforces the use of things like dependency injection, resulting in loosely ...
3
votes
1answer
64 views

GUI Testing With Network

I am doing GUI tests for my network application and I'm wondering if I should stub out mock responses, or if it's OK to keep using the network for the GUI tests. It seems to me the main benefits of ...
12
votes
6answers
2k views

In TDD should I have to write Test first or Interface first?

I am learning TDD using c#, as far as I know test should drive the development, that is first write a failing test after write the bare minimum code to pass the test then do refactoring. But it is ...
0
votes
0answers
67 views

Bringing in unit test code with Mocking Frameworks in an established ASP.NET C# software application

Here is the information about my development environment: MongoDB 3.0.0 MongoDB C# Driver Version 1.7.0.4714 Microsoft Visual Studio Professional 2013 .NET Framework 4.0 We are about to do our ...