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
3answers
144 views

How to explain to someone what unit tests are? [on hold]

I used to be a lot more pragmatic when trying to explain this sort of things to other programmers, but most of the time I was in situation where I could force them to just accept my will (tech lead, ...
14
votes
6answers
4k 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 ...
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 ...
3
votes
2answers
172 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 ...
-1
votes
0answers
46 views

Unit test framework dilemma [closed]

Until now, our company uses Google test for unit testing. Now we are developing, let's call it an add-on, which will interface with our existing product, but which we also want to keep generic enough ...
-2
votes
1answer
43 views

How to unit test access to a external service's client? [closed]

Say I am writing client for an external web service (like openweathermap). How should I unit test that? Say I have a class like : class WeatherClient { ... public Weather getCurrWeather(String ...
3
votes
2answers
184 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, ...
41
votes
9answers
10k 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
181 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
236 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
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
168 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). ...
0
votes
1answer
367 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 ...
1
vote
2answers
280 views

Testing front-end app that hits a REST service

A lot of questions about testing here... And I have another one. Forgive me, but I want to make sure I do this right. Let's say I have a front-end application, be it a mobile app, or a single-page ...
4
votes
2answers
119 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
884 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
101 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
4k 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
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. ...
8
votes
2answers
972 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
129 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 ...
5
votes
2answers
148 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
96 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
116 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 ...
10
votes
5answers
4k 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 ...
0
votes
2answers
144 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 ...
1
vote
2answers
278 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 ...
10
votes
4answers
430 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 ...
5
votes
6answers
2k 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
53 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
542 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
133 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
43 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 ...
7
votes
3answers
960 views

What should I mock in tests of an application with service tier and DAO tier?

My classes are following this structure Service Tier (creates and maps InputDTO to DB Data) DAO Tier (actually executes DB calls) When I write service tier JUnit tests, the DAO tier is called, and ...
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 ...
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 ...
7
votes
3answers
99 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 ...
0
votes
1answer
82 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 ...
23
votes
9answers
2k views

What are the disadvantages of writing code before writing unit tests?

I have always seen the recommendation that we should first write unit tests and then start writing code. But I feel that going the other way is much more comfortable (for me) - write code and then the ...
24
votes
5answers
10k views

What are the design principles that promote testable code? (designing testable code vs driving design through tests)

Most of the projects that I work on consider development and unit testing in isolation which makes writing unit tests at a later instance a nightmare. My objective is to keep testing in mind during ...
5
votes
5answers
2k 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 ...
77
votes
10answers
7k views

How to motivate co-workers to write unit-tests? [closed]

We're working on a large product which has been in production for about 5 years. The codebase is.. erm.. working. Not really well but it is working. New features are thrown into production and tested ...
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 ...
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 ...
0
votes
4answers
124 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, ...
2
votes
3answers
262 views

How much should I break up my unit tests?

I recently learned about unit tests and TDD and have started going back to add unit tests to my code (and thank god, it's proven that some things I've written are much more broken than I thought). ...
2
votes
1answer
91 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 ...