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
1answer
53 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 ...
0
votes
1answer
111 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
44 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 ...
-1
votes
0answers
41 views

how to write JUnit testing using inteliij idea? [on hold]

I am fresher in IT industry and new to writing tests specially of Junit testing tools.Can anyone help with few examples on Junit testing which will cover testcode on some complex programs
75
votes
12answers
9k views

Is testable code better code? [duplicate]

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
53 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
837 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
0answers
24 views

RSpec it block with variable name [migrated]

I have a function get_type that returns a string given an int: def get_type(integer) types = [...] return types[integer] end When testing with RSpec, I tried doing the following: describe ...
0
votes
4answers
110 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
256 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
83 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
66 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
106 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
1answer
78 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
828 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 ...
3
votes
2answers
99 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
516 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
49 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
30 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
733 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
80 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
66 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
63 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
138 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
157 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
248 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
117 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 ...
3
votes
1answer
103 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
50 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
51 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
264 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 ...
4
votes
1answer
85 views

Cons of using unconstrained frameworks for unit testing

It's very easy to write unit tests for legacy code using unconstrained frameworks, such as TypeMock Isolator. But what about writing unit tests for newly written code? Is it a good practice to use an ...
1
vote
2answers
223 views

How to unit test static void methods? [duplicate]

How does one go about unit testing static void methods? I have a few more questions: Is it necessary to unit test database queries like insert, select and update queries ? If so, how does one test ...
4
votes
1answer
164 views

How well am I writing my tests?

I've been coding as a career for about 2 years now but am just now writing my first "real" tests for a non-trivial application. I've been trying to follow best practices I've picked up from the ...
3
votes
5answers
206 views

Injecting collections as constructor dependencies

We are using constructor dependency injection in our application. Following that approach we inject everything using an injection container so we are able to replace any dependency with a Mock. Some ...
0
votes
0answers
34 views

Unit testing : verifying calls : is it a good practice for non-logic code? [duplicate]

I'm currently working on a Java project where many of our services simply call adapters, with no particular business logic. In the most extreme cases, the code of the service is simply return ...
0
votes
1answer
136 views

How do I actually use Selenium to automate UI testing? [closed]

We have a large inventory system where we work and making changes has the possibility to break things in other areas. This happens a lot, and it is hard to manually test for everything every time ...
1
vote
2answers
54 views

Verifying absence of an event in multithreaded unit test

I've got a legacy application that had a fragile unit test (which is really more of an integration test) that used a lot of Thread.Sleep calls to wait for events to happen. While trying to introduce ...
1
vote
1answer
106 views

How to unit test a top level method

I'm trying to unit test a small program I wrote. My problem is that I can't see an easy way to unit test my top level class (Matcher) that exposes a single public method (MatchAll). I do have tests ...
2
votes
1answer
65 views

How to unit test logic in crud app

Apologies if this question has been asked before, I've seen similar questions, but nothing quite the same. I am writing a web application which uses http calls to write and read from a back end ...
0
votes
0answers
106 views

DBUnit alternatives to test DAO layer

We have a lot of DAO tests written with DBUnit and (it's ugly) datasoure. It's not that hard to edit it and add some new entries but it's annoying. Worse is that we have only one datasource for all ...
6
votes
2answers
2k views

Is “Unit testing” a form of formal method?

After some research, I understand that: Formal method contribute to the reliability and robustness of a design. (ref : Wikipedia - Formal method) Unit testing ensures us of the absence of errors ...
10
votes
4answers
9k views

Should one use Dependency Injection even if the class is used only once? [duplicate]

During a code review I have started having a bit of a dilemma as to whether use dependency injection or not. I would like to hear your thoughts, because this is kind of an ongoing theme and would help ...
2
votes
2answers
170 views

Unit testing and reusing extracted class

Currently I have 3 service classes, they all have a similar pattern, and I need to make a 4th service class which amalgamates the functionality of the other three. Current three classes public class ...
6
votes
6answers
674 views

Why are my unit tests so expensive? [duplicate]

I am a Java developer, working on a small project. We are three people in the team, we have a budget for 3 months of coding (+ some time for the Analyst, Project Manager and QA team). It is a small ...
0
votes
0answers
66 views

Abstract Web API from validation and configuration management in embedded system

Im working with embedded Linux for a router. There is a web GUI for the user to configure router options. When user fill a web form this is submitted to a web server function that is responsible of ...
3
votes
2answers
203 views

How do you unit test \ use TDD methods for ETL's and reporting projects?

ETL projects are projects created using an ETL (Extract - Transform - Load) tool such as SSIS, PowerCenter,etc These typically involve reading data from an external source, loading it to a staging ...
5
votes
4answers
977 views

Is it a bad practice to separate the unit tests for a class? [closed]

My Classes normally have about 5-20 methods maximum, that implies that the class that has the unit tests has about the double of methods (counting dataProviders, setUp, ...) I have thought to ...
0
votes
1answer
241 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 ...