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)

4
votes
2answers
285 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) { ...
3
votes
2answers
182 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
188 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 ...
1
vote
1answer
53 views

Eclipse unit test - one project per file/class?

My new company has never had unit testing, but have finally been persuaded to introduce it. They have chosen Google test and, for some reason, want to run the unit tests from within Eclipse (where I, ...
33
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 ...
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 ...
3
votes
1answer
74 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
171 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). ...
5
votes
1answer
186 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 : ...
2
votes
1answer
242 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 ...
4
votes
2answers
120 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
889 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 ...
2
votes
0answers
88 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. ...
-1
votes
3answers
130 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
97 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 ...
2
votes
2answers
97 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
117 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 ...
1
vote
2answers
54 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 ...
1
vote
1answer
44 views

Website form testing [closed]

My boss has three websites and each of those websites have forms on them that people can sign up for nightclubs. He asked me to look up usability tests, however, I don't think that's what hes ...
0
votes
1answer
137 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 ...
1
vote
1answer
82 views

Focus of unit tests on code [duplicate]

I discover mocking strategies after 50% of tests was writen, and I'm confused about how much focus unit tests should have, for example on class method. I know that for external dependencies you should ...
1
vote
2answers
292 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 ...
0
votes
1answer
85 views

Unit testing implementation vs behaviour

Is it possible to write a unit test (as opposed to an integration test) in the following scenario: I have a list of Foo objects, some of which already exist in the database, some don't I want to ...
81
votes
12answers
10k views

Is testable code better code?

I'm attempting to get into the habit of writing unit tests regularly with my code, but I've read that first it's important to write testable code. This question touches on SOLID principles of writing ...
0
votes
2answers
59 views

Avoid FileUtil that is made for tests [closed]

I'm constantly creating util classes like Files to be able to mock files functionality in tests. It is convenient but violates basic idea - don't modify production code to comply with tests. I could ...
8
votes
2answers
977 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 ...
0
votes
4answers
125 views

Unit Testing for mapping int to string

How should one unit test a function which (among other things) maps an integer to a string? If the function were to map 0 => string0, 1 => string1, 2 => string2, should I test for each of 0, ...
7
votes
4answers
273 views

Testing a Conversion class

I have a class that is responsible for performing conversions from/to twenty-something types. Let's call this class ConvertUtils. For C# programmers out there - this class expands .Net's Convert ...
7
votes
3answers
100 views

How to write tests that make sense for visualization software?

I have a fairly large piece of software which takes certain file types and visualizes them / creates a host of buttons for manipulation of the image plotted. I feel like I'm finding bugs / pieces of ...
2
votes
1answer
94 views

Javascript unit testing - mocks or fixtures?

Interested in some opnion... I'm introducing unit testing of JS into a team, it'll largely be testing modules with many dom interactions and updates. Traditionally I've always used mocks and spys ...
1
vote
3answers
150 views

Unit testing functions calling other tested functions [duplicate]

I have three functions: ValidateUsername(), which determines if a string is a valid username according to some rules SetUsername() which sets a string as a user's Username if it passes validation ...
0
votes
2answers
147 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 ...
15
votes
2answers
882 views

Shipping test code. Why wouldn't you?

I would like to ship unit tests alongside a product. Specifically, provide an option so that anyone with a copy of our program can hit a "self-test" button or pass --self-test on the command line and ...
5
votes
2answers
151 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 ...
34
votes
6answers
4k views

How can I write unit tests that simplify feature implementation? [duplicate]

I'm a newbie to working in software development and I read a lot about how cool unit tests are. Now, I've made my first steps into a project where I'm working with a number of equally unexperienced ...
5
votes
4answers
540 views

How to write a test to cover a bugfix of a segfault

There was a bug that I recently fixed that was causing a segmentation fault (due to an out-of-bounds access). The maintainer of the project is asking me to write a unit test to cover the bugfix. How ...
1
vote
1answer
61 views

What is a good alternative to the TestDataBuilder pattern?

The TestDataBuilder pattern is used in unit testing to create collaborators. Its advantages versus using constructors: Changes to constructors are localized. Test code becomes clearer, because you ...
0
votes
0answers
35 views

Mocking delegate constructors

I am new to Unit Testing in C++. I am supposed to write a Unit test for my code and I am using Google Mock for the same. I have gone through their turtle example. But I am still confused as to how to ...
11
votes
3answers
752 views

Unit Testing Competition

My employers runs a monthly unit testing day competition. One entire day is dedicated to writing unit tests -- obviously we do more testing throughout the month, but this is an entire day -- and the ...
2
votes
2answers
108 views

Testing strategy for wrapper class

In my Android project I decided to create wrapper around SharedPreferences(which is basically key-value storage) with following interface interface Preferences{ public void saveInt(int value, ...
4
votes
2answers
80 views

How to decide what forms the System Under Test

Ok, so we started with the initial version of "The Art Of Unit Testing" and we do unit tests for classes where every test covers one aspect of one method. This has the drawback of high maintenance ...
0
votes
0answers
85 views

How to verify a method is only called once, with specific arguments (using RhinoMocks)

I'm just starting to use RhinoMocks. Now I'm wondering what test cases I should write. I want to assert that a method is only being called once, with specific arguments. Lets start with my ...
3
votes
2answers
167 views

Domain object model: query by id vs object

Let assume I have two simple model classes: Product and Brand It is obvious I have a query method in Product class like this Product product = Product.findById(123); What if, I want to query ...
2
votes
2answers
170 views

Example of writing unit test for a method

I am writing unit tests for an iOS application. I clearly understand the benefits of writing unit tests & TDD, but I am confused about what kind of tests you can write for methods like this; ...
6
votes
3answers
332 views

Advantage/Disadvantage of having all variables declared in a JUnit Test

I've been writing some unit tests for some new code at work, and sent it off for a code review. One of my co-workers made a comment about why I was putting variables that are used in a number of those ...
1
vote
5answers
121 views

Unit-testing on higher levels of architecture

tl;dr: Libraries and classes I use as client are well tested. How I can use that knowledge to reduce amount of testing? Elaboration: Let's assume for theoretical purposes that we're implementing ...
4
votes
1answer
147 views

Is contructing complex mocks for unit testing a sign of bad architecture?

The title is fairly self explanatory. To elaborate: I'm currently updating a suite of unit tests for an application which makes heavy use of Entity Framework. We connect to this via a classic ...
0
votes
2answers
74 views

Testing binary stream

I am building a binary file importer using Python. The specific file structure is defined in a specification. This looks like: File Map Block String, Short Integer, Long Integer, String, Short ...
0
votes
2answers
57 views

Defects Review and Management

The doubt or question i have is something every developer might be facing time to time. it is related to testing and development team and their perspective. I have observed that most of the Defects ...
1
vote
5answers
282 views

Are mocks in unit tests dangerous in dynamic languages?

I've started relying heavily on a mocking framework in php for my unit tests. My concern is that with a dynamic language, there is no way of enforcing a return type. When mocking, you have to ensure ...