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
2answers
107 views

Unit Testing and 3rd party packages. Do I mock or not?

I'm just getting used to unit testing and on my new project I decided to adopt a TDD approach. My code below is to test the UserServices class which is responsible for creating a user, deleting a ...
0
votes
0answers
47 views

Where do you put your profiling code?

I just developed an algorithm and additional to the usual unit tests I wrote a profiling "test" that I was using to measure and optimize its performance. It is structured similar to a test (arrange: ...
0
votes
0answers
8 views

Running unit tests for an Azure solution built by TeamCity

We have a solution containing a Web Role and Worker Role. This is built by TeamCity and deployed by Octopus Deploy to a Microsoft Azure environment. The solution contains unit test assemblies (MSTest) ...
0
votes
2answers
145 views

Should a Junior programmer add TDD tests to mvc project

I'm a junior programmer near to my 6 month probation, following my initial career changing 3 month assignment in which I added TDD tests and wondering whether I should add tests to my current work. ...
-2
votes
3answers
131 views

What is the most elemental workflow for TDD?

Gradle is such an interesting build tool that it prompted me to look at Spock and JUnit -- which I've never done before. What is the basic workflow with TDD? My approach has been to do frequent ...
4
votes
3answers
80 views

Unit Testing Module-Internal Functions

I'm writing a simple whitebox unit testing suite for a project I'm working on in C. The project is broken into modules (each has a .c file with an associated .h file), and all modules are compiled ...
4
votes
1answer
73 views

When does it make sense to include test code in coverage?

Many coverage tools evaluate an entire project, including unit test code itself. In VS 2013, the Analyze Code Coverage/All Tests option includes test code in its report. OpenCover does so as well I ...
4
votes
2answers
107 views

What is it called when you test a microservice by mocking the dependencies?

I've a RESTFul microservice written in Grails. This microservice has it's own DB. It also depends on two other microservices. A typical workflow of the service is: Receives a GET request from a ...
4
votes
1answer
51 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 ...
4
votes
2answers
87 views

How do you evaluate automated testing for a particular product/project?

Automated testing is pretty hyped-up in recent years, with particular emphasis on TDD at the "unit" level. The touted advantages include things like: Stabilizing existing code: breaking changes are ...
2
votes
4answers
136 views

Cleanup & Arrange practices during unit testing to avoid dirty databases

I'm coding UnitTest in C# and I settled with this structure: try { // ========== // ARRANGE // ========== // Insert into the database all test data I'll need during the test // ...
2
votes
1answer
81 views

How far do I, or can I take TDD tests with Service Objects?

In writing PHPSPEC tests for a Zend Framework 2 application, I'm left wondering how far to 'dig'. Consider this very simple case: A DomainService (Domain in the URL sense of the word) should be ...
76
votes
9answers
8k views

What's the point of running unit tests on a CI server?

Why would you run unit tests on a CI server? Surely, by the time something gets committed to master, a developer has already run all the unit tests before and fixed any errors that might've occurred ...
1
vote
1answer
45 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 ...
2
votes
2answers
122 views

Differences between Given When Then (GWT) and Arrange Act Assert (AAA)?

In TDD there is Arrange Act Assert (AAA) syntax: [Test] public void Test_ReturnItemForRefund_ReturnsStockOfBlackSweatersAsTwo_WhenOneInStockAndOneIsReturned() { //Arrange ShopStock shopStock ...
0
votes
3answers
109 views

At what point in a projects life-cycle do you begin writing tests? [duplicate]

I'm not in the field, so I don't have any professional experience from projects following the TDD design. I am trying to adopt this pattern, but I'm confused as to when I start actually writing the ...
1
vote
1answer
48 views

How can you easily unit test deserialization to different versions of an object?

I am using the protobuf-net library for serialization/deserialization of messages. Due to the distributed nature of the application some applications will have an older version of the object that is ...
7
votes
1answer
98 views

Unit Testing: Assembler code and different architectures

I am currently unit testing some C code and I am faced with a problem: Within the code there are called functions that contain inline assembler code for the SPARC 8 architecture. Since I am doing ...
5
votes
2answers
264 views

How does breaking up a big method into smaller methods improve unit testability when the methods are all private?

I'm presently reading Building Maintainable Software by Joost Visser and some of the maintenance guidelines they recommend include: A) each unit/method should be short (less than 15 lines per method) ...
3
votes
3answers
114 views

How do you test a selenium framework?

I have a very large selenium test framework I use to test a web application. It it built around a page-object pattern. This week I fixed a bug in a low level piece of the framework, but it broke many ...
1
vote
2answers
67 views

how to unit test constant that define an implementation detail?

How do I unit test a constant that define an implementation detail? and should I? For instance let's say I have the following class: class A { private Cache _cache; const int ...
2
votes
2answers
103 views

How unit test service method that use repository method

For service methods that call repository methods to interact with database how could I unit test these service methods? For example, public function updateSlideshow($data){ // do some logic ...
8
votes
3answers
286 views

Anonymous namespaces make code untestable

Here is a typical C++ code: foo.hpp #pragma once class Foo { public: void f(); void g(); ... }; foo.cpp #include "foo.hpp" namespace { const int kUpperX = 111; const int ...
6
votes
2answers
946 views

Should I write automated unit tests that fail when the code changes?

Generally when writing automated unit tests (eg JUnit, Karma) I aim to: cover all the boundary conditions get a high level of coverage. I heard someone say: coverage and boundary conditions ...
13
votes
5answers
493 views

Broken Old/Legacy Unit Tests

I work for a big company and I'm responsible for a large java application with thousands of junit tests. Since I moved to this role, there have been 200-300 broken tests (likely broken for years). ...
2
votes
2answers
56 views

Having a TestContext to test methods instead of Dependency Injection

I am working on a legacy code base and I need to find a way to write unit tests for this project. The project has a three layer architecture (UI-Biz-DAL as we call them) and DAL is totally ...
1
vote
2answers
81 views

Testing using mocking, must I mock all dependencies too?

I have the following method to test: public List<MarkId> getMarkIdList(ICar carDoc) { ICourseCar courseCarDoc = courseCarRep.get(carDoc); List<MarkWag> markWagList = ...
4
votes
3answers
162 views

How narrow should my unit tests be?

Here's an example: I have a chat module in my app, and there's a ChatService class that is responsible for networking, and there's a ChatNotificationService helper class that is responsible for ...
5
votes
1answer
88 views

Unit testing an API client and wrappers

I've been going round in circles trying to figure out the best way to unit test an API client library I'm developing. The library has a Client class which basically has a 1:1 mapping with the API, and ...
3
votes
1answer
92 views

How to move Python doctest examples into another unit test framework?

Years ago AFAIK the mathematitician and software developer Tim Peters discovered that very often the documentation of APIs tends to get out of date over time during the software live cycle, because ...
5
votes
0answers
63 views

Unit testing for data munging pipelines made up of one-line functions

Reading Mary Rose Cook's Practical Introduction to Functional Programming, she give as an example of an anti-pattern def format_bands(bands): for band in bands: band['country'] = 'Canada' ...
0
votes
1answer
45 views

Reusing array with static test data across test classes

I have a Map which takes in an a String key, and an array of custom objects as the value. the map usually contains two entries, and the arrays for both entries never change in terms of data; once they ...
32
votes
9answers
2k views

Is it reasonable to not write unit tests because they tend to get commented out later or because integration tests are more valuable?

I was discussing unit/integration testing with a colleague, and he made an interesting case against writing unit tests. I'm a big unit test (JUnit primarily) proponent, but am interested to hear ...
-1
votes
2answers
116 views

What technique can I use to test my code when code renders out an untestable(?) PDF document?

I have a need to test output of my code before I send the output for PDF rendering. Currently I have decided on a switch statement that does two different things depending on whether I am in ...
0
votes
2answers
145 views

Integration Tests - How much is too much? [duplicate]

First of I'm not sure if I chose the right name for my question, I'm not sure if they are functional tests or integration ( or other ). I'm talking about tests which test (or it should) the app from ...
2
votes
1answer
52 views

Best Possible Way To Write Unit Tests For HTTP Middleware

I am using this go library(https://github.com/abourget/goproxy) to create a custom proxy server app. The app is utilizing several middleware of the following form: MyMiddlewarFunc(ctx ...
5
votes
6answers
539 views

Is it an overkill to write unit tests for a small code base? [duplicate]

I am the sole maintainer of a code base of about 2000 lines of code. It's not big, but over time the code became so unmaintainable my boss agreed to give me time to rewrite it from scratch. Since the ...
5
votes
2answers
115 views

Mocking a utilities module for unit testing? [duplicate]

I'm writing unit tests for a class that makes use of a general utilities module. In general I want to mock all the dependencies of the class, but mocking some of the utility functions feels weird. ...
2
votes
4answers
135 views

Is it ok to use service locator for ubiquitously used dependencies? [closed]

We strictly adhere to inversion of control in our codebase, but that creates hellish constructors (yes, I know that means our classes aren't cohesive enough, this is a work in progress). The thing is, ...
5
votes
1answer
116 views

Testing procedural code

TL;DR. Writing procedural code within a DB transaction. How can I improve design of the code so it's better testable? In my application I have a service object that perform multiple things within the ...
4
votes
2answers
98 views

Does one need to mock concrete data objects?

I've been working on a large project where much of the code is not under test. I have been able to add some unit tests to functional areas of the code, and also to start mocking services but I have a ...
0
votes
1answer
141 views

Testing a function that only calls one or two other functions [duplicate]

The short version The code As part of TDD, we often end up with functions that follow this pattern: function onSendRequestForSelected() { this.deselectStepsWithRequest(); ...
0
votes
1answer
98 views

How to write unit tests for an application that mostly performs “hard to test” actions? [duplicate]

In my company we develop medical data-acquisition systems. The main functions of each application are: Interface with data-sampling hardware; Save/load collected data to/from files on disk; Perform ...
1
vote
0answers
24 views

Do the terms “unit test” and “integration test” sometimes overlap or conflict? [duplicate]

By my understanding, a "unit test" is a test that makes assertions about the "smallest testable unit" - and an "integration test" is a test that depends on integration with an external system, e.g. ...
1
vote
1answer
84 views

Testing base-62 converter

I have a converter module which encodes non-negative numerics to base 62 strings and vice versa. I'm not very experienced with testing, and I got this so far: Encode Test for negative numbers Test ...
0
votes
1answer
57 views

How big should be an input array to unit test a method with a loop? [closed]

This probably sounds like a dumb question, forgive me if I'm asking this in the wrong place, I'd be happy to delete it if so. I'm sort of new to unit testing and I'd like to learn best practices ...
3
votes
0answers
64 views

How to properly test many methods when main logic is in private method [duplicate]

This is a little bit of follow up question to How to test private methods. I totally agree (and experienced what happens when you try) that we should not test private methods. Sometimes though it ...
1
vote
3answers
153 views

How should you look at unit testing protected members used by the abstract base class?

I have the following class(es) that I want to write unit tests for: public abstract class BaseClass { public bool IsFooBar(Order order) { return order.IsNew && ...
1
vote
1answer
75 views

Unit test structure focused on responsibilities

I'm not going to ask what is the best unit test structure or how to do it again. There are already enough questions about it. Instead I'd like you to tell me what else I could consider in the ...
2
votes
3answers
141 views

Is it considered a bad coding practice to write methods/properties that support (only) testing? [duplicate]

When I write (unit) tests I always try to avoid for example microsoft fakes because then the edit&continue feature no longer works. However this often requires refactoring... and sometimes methods ...