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)

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
30 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
47 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
76 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
71 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 ...
-1
votes
0answers
28 views

Cover term for tests and benchmarks [closed]

What is the cover term for (unit) testing, benchmarks or anything that runs the functionality to see the outcome? Some words that come to mind is evaluation, assurance, measurement. But I am not ...
3
votes
2answers
144 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
155 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
244 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
109 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
115 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
115 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
145 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 ...
-1
votes
0answers
39 views

Writing an Overall test plan for a system?

I need to write an overall test plan for a system outlining our strategy for Verification and validation testing. In this document i need to include a strategy for unit testing, integration testing ...
1
vote
1answer
848 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 ...
4
votes
1answer
128 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
85 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
94 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
114 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
122 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
103 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
2k 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
698 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
62 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
57 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 ...
5
votes
2answers
131 views

The concept of “quality gates” in software testing

We are using SonarQube for code quality testing. It tests the quality of code, and not the function of code. It has the concept of quality gates, so you can set for instance a 90% quality gate, ...
4
votes
3answers
159 views

What kinds of bugs can integration testing actually find?

I feel like, in web dev at least, that integration tests can't really find any useful bugs. I can't think of any, at least. If I can use unit tests to verify that one section of my code calls a ...
3
votes
1answer
58 views

How do you properly test a complete software replacement

We have System A (an application and a database) that is built for a specific business department and therefore has business aligned data model and table structure. System A is a mission critical ...
2
votes
2answers
124 views

Are DDD aggregates a good boundary for unit testing?

An aggregate can represent a somewhat stable system boundary. Does it make sense to write input and output test aggregates to do most testing? In theory we could use an aggregate as a data driven way ...
2
votes
0answers
46 views

Dealing with conditional verification logic using guard assertion

I have parametrized test with 2 variants: NULL value and any NOT NULL value From this value is depends one assert: In case NULL it should be checked if object has field1 with value1 In ...
89
votes
14answers
12k views

When is it appropriate to not unit test?

I work in a small company as a solo developer. I'm the only developer at the company in fact. I have several (relatively) large projects I've written and maintain regularly, and none of them have ...
18
votes
1answer
10k views

How to set up Unit Testing in Visual Studio 2010? [closed]

I'm doing my first big project and I don't have a lot of experience in a professional programming environment. While researching anything programming-related I often see references to Unit Testing, ...
4
votes
1answer
196 views

How to Structure Simple C++ projects for TDD

I am introducing Google Test into our development environment at work, and would like to encourage a TDD mindset, making this as accessible as possible for new developers to start using. I am looking ...
3
votes
1answer
93 views

Unit testing a large project with few publicly accessible components [duplicate]

I'm asking about C#, but this probably applies to most other languages as well. Imagine I have a project with a lot of complex logic, split up into a lot of small components. Let's say that, among ...
-1
votes
1answer
123 views

What is the difference between a mock and a test double? [closed]

I was reading an article here on Mocks. I would like to conclude to make my understanding more clear. Anything that can be placed in place of a real object while testing is called a Test Double. ...
2
votes
1answer
113 views

Using Spring in Java Project

I've got a question about a correct usage of Spring. I know that some people use the DI "aggressively" so that they always use spring and completely eliminate the usage of word "new" in the ...
0
votes
0answers
52 views

Testing $stateChangeStart

I'm trying to figure out how to test my $rootScope.$on.$stateChangeStart event. Authentication service already has unit tests to check it's functionality, but I'm really trying to do is set up a test ...
3
votes
0answers
81 views

How to think about a schedule that pulls from a database as objects

I am working on a personal project using Python. I have been using version control to the best of my abilities and if you would like to check it out and run the app ...
5
votes
2answers
179 views

Respectable design pattern for making node modules flexible/testable?

I am looking to get some input from some more experienced testers than what I am. :) I am trying to make my node modules testable, allowing for dependency spying/stubbing/mocking without the need to ...
1
vote
1answer
38 views

Automated test for code that takes a bunch of input data and outputs a bunch of data - should it be split up?

I'm about to write a program and test(s) for it. This question is about how to structure the top-most level integration test. At the top level, the main program takes a chunk of data, and outputs ...
57
votes
11answers
32k views

Is static universally “evil” for unit testing and if so why does resharper recommend it? [closed]

I have found that there are only 3 ways to unit test (mock/stub) dependencies that are static in C#.NET: Moles TypeMock JustMock Given that two of these are not free and one has not hit release ...
8
votes
6answers
4k views

Why do I need unit tests for testing repository methods?

I need to play devils advocate on this question a bit because I cannot defend it well because of lack of experience. Here is the deal, I get conceptually the differences between unit testing and ...
21
votes
4answers
2k views

How can CI be used for interpreted languages?

I have never used a Continuous Integration system (CI) before. I primarily code in MATLAB, Python or PHP. Neither of these have a build step and I do not see how a CI could be used for my work. A ...
5
votes
7answers
403 views

Is it appropriate to not follow the O/C principle if you have unit test coverage?

I find it more convenient to 'modify'existing classes rather than extending them. Thus, I violate the open closed principle of 'not modifying the compiled and tested source code, instead extending the ...
7
votes
1answer
196 views

How should the code for a program outputting to command line be tested/designed?

Imagine a program similar to this in Python: import subprocess class Example(): _cmd_args = (['ls', '-a', '/usr/bin/'], ['ls', '-al', '/usr/local/bin/']) _default_args = 0 def ...