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)

0
votes
1answer
53 views

How to write loosely coupled tests [duplicate]

I work on a software that has a lot of tests. However, instead of helping us develop faster, these tests actually bog us down, because even tiny changes in the application break many tests. Clearly, ...
1
vote
0answers
51 views

Unit testing and testing null value [duplicate]

I m actually studying unit testing and I was wondering if testing null value is good or not in every functions / method of my app. Admitting that we're working on javascript and that I have a ...
3
votes
3answers
104 views

Unit Testing a Function which produces “limit less” results

I am pretty new-ish to unit testing in a more nuanced sense. If have an application function which based on users given input could produce an seeming "limit-less"combination of output, whats the ...
1
vote
0answers
108 views

ASP.Net MVC - Implementing a Test Environment

I would like to implement some sort of test environment for ASP.Net projects. I am trying to implement this as an alternative to mocking the entity framework. Here is what I am trying to achieve : ...
12
votes
3answers
776 views

How to draw programmer's attentions in certain conditions?

Let's start with an example. Let's say, I have a method called export that depends heavily on the DB schema. And by “depends heavily” I mean I know that adding a new column to a certain table often ...
158
votes
16answers
16k views

Why does automated testing keep failing in my company?

We have tried to introduce developer automated testing several times at my company. Our QA team uses Selenium to automate UI tests, but I always wanted to introduce unit tests and integration tests. ...
0
votes
0answers
109 views

Unit Testing in iOS — Should I split out my Data Model into its own class?

I'm attempting to try out using unit test in for the first time in new iOS activity for work. I love the idea of unit testing, but always find the specifics to be... messy. I get the general ...
2
votes
3answers
153 views

automatic database fill up in sql script tests

The problem I am working on an application with ~ 1000 tables in a sql server database. I am having a recurring issue with a sql script. The script is used by the consulting team to "clean" some ...
1
vote
1answer
93 views

Should I share test code between different repositories [closed]

Suppose I have a Repo A that imports a Repo B. I maintain both of them. Currently, I have some convenience functions that are useful for testing of both repos. They live in Repo B's test directory. ...
2
votes
2answers
204 views

Writing your test assertions in your function comments (just before the code)?

I'm using PHP and PHPUnit. Something bothers me: the fact that the assertions are in another class (too easy to forget or to ignore, for any new programmer in the project). If the test assertions ...
0
votes
1answer
102 views

How to test a REST service without being excessive

So I have a REST backend (in node.js or Java doesn't matter but the example is in js). I try to have a service for each endpoint so that the /users endpoint has two files: usersRouter.js which ...
3
votes
2answers
317 views

Should I also mock header files?

So, I am part of a very large project which has, as yet, no unit testing (shudder!) and I want to introduce it. I plan on using Google Test and Google mocks. The code is large and unwieldy and ...
5
votes
2answers
1k views

Unit testing behaviours without coupling to implementation details

In his talk TDD, where did it all go wrong, Ian Cooper pushes Kent Beck's original intention behind unit testing in TDD (to test behaviours, not methods of classes specifically) and argues for ...
7
votes
6answers
794 views

“Anything can go wrong will go wrong” - Murphy's Law. so is it necessary to test all the conditional, exception cases? [closed]

If "Anything can go wrong will go wrong" is true, we need to test all the conditionals and exceptional cases in my code. But sometimes it's hard to find all of them since many of them are corner ...
1
vote
2answers
177 views

When is documentation, unit testing, QA and refactoring meant to be done in a 2 week agile sprint?

The team I am working on is trying to do agile development with 2 week sprints. I think we must be doing something wrong however, as we have to work like madmen to get the features implemented in the ...
5
votes
2answers
190 views

Is there a benefit to unit testing code whose sole purpose is to generate non-human-readable code in another language?

A significant portion of the application I work on every day consists of Javascript that outputs a lot of (what might as well be) Excel spreadsheet formulas. Yes, Excel is barely a Turing-complete ...
5
votes
4answers
239 views

In CI, should tests be run against src or dist?

I've had a dispute with a colleague about when to run JavaScript unit tests in a CI environment at one of two different times. Let's call the two parties PE (pro-early) and PL (pro-late). Early ...
16
votes
4answers
37k views

Best way to unit test methods that call other methods inside same class

I was recently discussing with some friends which of the following 2 methods is best to stub return results or calls to methods inside same class from methods inside same class. This is a very ...
0
votes
2answers
69 views

Best practices for testing deep objects?

I'm writing in javascript with 'should' library, but this doesn't matter. I should write test for method, which returns a quite big object with a lot of fields. How I should write my expected result? ...
10
votes
3answers
3k views

How to unit test method that returns a collection while avoiding logic in the test

I am test-driving a method that is to generate a collection of data objects. I want to verify that the properties of the objects are being set correctly. Some of the properties will be set to the same ...
4
votes
2answers
343 views

What to do with my unit tests when refactoring code to a new class

I hope I can make a clear question... I've simplified my code example for this question, I hope it still makes sense. public class PersonComponent { public bool IsQualified(Person person) { ...
15
votes
6answers
6k views

Why did Java make package access default?

I'm asking this question because I believe they did it for a very good reason and that most people do not use it properly, well from my experience in industry so far anyway. But if my theory is true ...
35
votes
7answers
4k views

Is there a need to keep tests for simple (self-contained) functions?

Consider this: public function polynominal($a, $b, $c, $d) { return $a * pow($x, 3) + $b * pow($x, 2) + $c * $x + $d; } Suppose you write various tests for the above function and prove to ...
3
votes
2answers
404 views

Converting static utility class into singleton

In company where I work we have lots of "utility" classes, each has lots of code inside (thousands of lines), and they are all static. And one static methods call anothers. The problem here is that ...
3
votes
2answers
320 views

Unit Testing without DI

I am starting a small ASP.NET MVC project, each task on the board must come with unit tests. The project is small, just a few pages with not that much processing, so I decided not to implement DI. My ...
44
votes
9answers
12k views

How to write “good” unit tests?

Triggered by this thread, I (again) am thinking about finally using unit tests in my projects. A few posters there say something like "Tests are cool, if they are good tests". My question now: What ...
13
votes
4answers
1k views

Do mocks violate the Open/Closed principle?

Some time ago I read, on a Stack Overflow answer that I can't find, a sentence that explained that you should test public APIs, and the author said that you should test interfaces. The author also ...
5
votes
1answer
274 views

How should I test the HTML output my class creates?

As a learning project, I am trying to create something similar to the WebGrid that comes with ASP.NET MVC. Now this component MyGrid<T> looks like this: public class MyGrid<T> where T : ...
3
votes
1answer
346 views

Testing private methods as protected

I was reading this answer about testing private methods and it mentioned several possibilities: extract methods as public to another class make them public separate the env of test and production ...
3
votes
1answer
95 views

Code Coverage or Test Brevity?

I've been writing a lot of unit tests lately and have become somewhat obsessed with code coverage. However, I'm struggling justifying going for 100% code coverage, when so many tests would be a ...
4
votes
1answer
206 views

Why do Unit Testing Attributes usually require public Methods?

I recently noted that adding [TestInitialize] to a protected method in a .NET assembly wasn't respected, but if I made the method public it was called by the unit test runner (Resharper in this case). ...
4
votes
2answers
190 views

Are Integration Tests Meant to be Redundant?

Here is some fake code under test: public void saveItem() { try { databaseInterface.saveItemToDatabase(item); } catch (Exception e) { // deal with it return; } ...
15
votes
2answers
924 views

Is it ok to avoid testing base classes?

I have a base class with a fair amount of "meta programming" to give it the flexibility/abstraction it needs to be rather generic. I do have a lot of subclasses using the common methods in the base ...
1
vote
1answer
138 views

how to unittest with thorough test coverage [duplicate]

I am trying to get into unit testing with python (though my question is not specific to python). I want to add a test for function I already have - I know I should do it the other way round, but here ...
22
votes
13answers
5k views

How does unit testing work?

I am trying to make my code more robust and I have been reading about unit testing, but I find it very hard to find an actual useful use. For instance, the Wikipedia example: public class TestAdder { ...
2
votes
0answers
161 views

How do I test with multiple input combinations?

I have a piece of code that I need to test, which is layered in three parts: Web API Controller Persistence/Logic Layer System calls for persistence It's the basic GET/POST/PUT/DELETE call system. ...
8
votes
2answers
1k views

Unit Testing with massive lookup tables?

Our system is structured in such a way that we get a lot of key info for our calculations and other such logic from lookup type tables. Examples would be all kinds of different rates (like interest ...
-1
votes
3answers
162 views

Who should write Unit Tests? [duplicate]

Should unit tests be written by the developer who wrote the code or someone else ? And how effective is writing units tests as a method of learning a new system ?
0
votes
1answer
120 views

Bad idea to use the same test cases for multiple parts of a contiguous algorithm?

I'm working on an algorithm that's split up into multiple parts, each of which performs different tasks but is more or less separate from the others, by which I mean the only interaction between the ...
5
votes
2answers
222 views

How to setup build system for unit testing + mocking?

We have a legacy code base in entirely C++. Our build system is CMake. My first stab at unit testing was as follows: Define a target (LibraryA). This library contains the code to test. Define a unit ...
2
votes
2answers
165 views

Should unit tests run on every git branch?

I am new to repo management / continuous integration. I designed a repo in the following way PROJ |-src |-include |-lib |-config PROJ_Unit_Tests |-src |-config PROJ_Doc When I now do ...
2
votes
3answers
197 views

Unit testing text output

I have recently become responsible for a legacy tool that analyses code and provides a log as output. As part of the JUnit suite for this, there are ~100 tests that rely on successfully matching the ...
11
votes
5answers
5k views

Are RSpec and Cucumber really worth it?

I know most RoR programmers are testing addicts and I understand the advantages of a large testing suite but when I start testing, I never get such a large suite and I always wonder "Am I testing the ...
1
vote
2answers
265 views

Testable design in Swift

I've been searching for so long about how to design testable classes in Swift but every information site just describe basic stuff like how to test, how to assert, why is testing good... My current ...
2
votes
2answers
831 views

BDD, Cucumber best practices

I'm trying to understand some best practices when it comes to BDD and Cucumber. I've only recently started to use it, and the first feature I have written a test for is testing a search feature, more ...
11
votes
4answers
446 views

What to do when TDD tests reveal new functionality that is needed that also needs tests?

What do you do when you are writing a test and you get to the point where you need to make the test pass and you realize that you need an additional piece of functionality that should be separated ...
6
votes
6answers
3k views

Are HSQLDB unit tests an anti pattern?

HSQLDB is great. It (also) has an embedded mode (no dedicated server needed), which allows for quick prototyping of stuff like Proof of Concepts, and it can also be great in production-ready ...
1
vote
2answers
105 views

Is the use of a constant as a parameter of an Unit Test mocked dependency's method wrong?

We have a Unit Test Case where we want to assert that after a login operation, the SUT is able to call a method on one of it's dependencies. This dependency is a NavigationManager and the expectation ...
2
votes
2answers
553 views

Is there a better way to organize my module tests that avoids an explosion of new source files?

I've got a neat (so I thought) way of having each of my modules produce a unit-test executable if compiled with the -DTESTMODULE flag. This flag guards a main() function that can access all static ...
0
votes
1answer
346 views

Will TDD really save bug fixing time for WPF/MVVM

I'm looking for an update .net 4.5 WPF+MVVM+TDD tutorial for my team. I have found only one good tutorial https://deltaengine.fogbugz.com/?W199 My goal is to learn Test Driven Development using WPF ...