Questions tagged [testability]

49 questions
236
votes
19 answers

How to test methods that call System.exit()?

I've got a few methods that should call System.exit() on certain inputs. Unfortunately, testing these cases causes JUnit to terminate! Putting the method calls in a new Thread doesn't seem to help, since System.exit() terminates the JVM, not just…
Chris Conway
  • 55,321
  • 43
  • 129
  • 155
32
votes
6 answers

inheritance vs. composition for testability

While designing my objects I find composition to be a better choice from the perspective of testability. The reason being, I can mock parts of the composition structure if I need to, while running unit tests. This is not possible if I have an…
Parag
  • 12,093
  • 16
  • 57
  • 75
15
votes
4 answers

Do Extension Methods Hide Dependencies?

All, Wanted to get a few thoughts on this. Lately I am becoming more and more of a subscriber of "purist" DI/IOC principles when designing/developing. Part of this (a big part) involves making sure there is little coupling between my classes, and…
11
votes
2 answers

Scala testable code with inheritance and mixins

I've developed a lot of code in Java and dabbled in Groovy and Haskell which has now led me to Scala. I feel relatively comfortable with the functional side of Scala, but I'm finding myself a bit shaky on object oriented design in Scala, because it…
Erik Madsen
  • 1,913
  • 3
  • 20
  • 34
11
votes
4 answers

Patterns for making c++ code easy to test

Should you design your code to make testing easier? And if so how to design c++ code so that it is easy to test. How do you apply dependency-injection in c++? Should I implement the classes using a pure interface class as the base in order to…
Joakim Karlsson
  • 1,112
  • 1
  • 15
  • 27
10
votes
2 answers

Scala: How to test methods that call System.exit()?

I have been developing a command-line tool which calls System.exit() (don't want to use exceptions instead of) on certain inputs. I am familiar with Java: How to test methods that call System.exit()? and its the most elegant approach. Unfortunately,…
sergiusz.kierat
  • 139
  • 1
  • 10
8
votes
3 answers

Should static classes be avoided because it makes Dependency Injection Difficult?

Somebody tasked with creating a "Core" set of libraries created a set of static classes providing all sorts of utilities from logging, auditing and common database access methods. I personally think this stinks because we now have a Core set of…
Ryu
  • 8,641
  • 10
  • 65
  • 98
8
votes
2 answers

The proper way to do Dependency Injection in a Windows Client (WPF) Application

I am used to IoC/DI in web applications - mainly Ninject with MVC3. My controller is created for me, filled in with all dependencies in place, subdependencies etc. However, things are different in a thick client application. I have to create my own…
8
votes
1 answer

Node.js: exporting class/prototype vs. instance

As I do most of my programming in Java, I find it compelling to export a class in a Node.js module instead of an object instance, e.g.: class Connection { constructor(db) { this.db = db; } connect(connectionString) { …
mingos
  • 23,778
  • 12
  • 70
  • 107
7
votes
2 answers

Where does one hold service instances in a react/redux application?

Suppose I am writing an application in Redux and I am tasked to add logging using a 3rd party library. Its API is as follows: function createLogger(token) { // the logger has internal state! let logCount = 0; return { …
VoY
  • 5,479
  • 2
  • 37
  • 45
5
votes
3 answers

It is possible/productive enough to TDD in C++ projects?

I want to know if anyone of you guys use TDD in your c++ projects and how it performs compared to managed languages like C# and Java. And what frameworks you guys are using to automate tests on c++ projects?
Diego Correa
  • 767
  • 2
  • 9
  • 22
3
votes
2 answers

Where to move constructing of disposable dependencies to improve testability?

In my unit tests, I use things like AssemblyInitialize, ClassInitialize and TestInitialize to configure my tests. In AssemblyInitialize I initialize some singleton factories for creating services, a unit of work and repositories (all trough…
Wouter de Kort
  • 39,090
  • 12
  • 84
  • 103
2
votes
1 answer

MEF and Factory Pattern

i am trying to refactor my project to improve testability, therefor i'm introducing an abstract factory. My application collects data from different sources by using ICrawlers. These ICrawlers use 3rd party libraries to access different sources,…
Stefan
  • 1,486
  • 2
  • 13
  • 19
2
votes
0 answers

Verifying the original value of an argument property with Mockito, before it's changed by another thread

I'm writing a test for my server with Mockito. In my test, instead of a real Messenger (which would try to send actual HTTP messages to a client), it uses a mock Messenger. The problem I'm facing is, one of the server methods basically does this (in…
Keenan Pepper
  • 321
  • 1
  • 3
  • 10
2
votes
3 answers

How make code that uses global dynamic properties unit testable?

A lot of code needs to use some global flag or properties to control the flow of the application. It is necessary for a lot of scenarios to maintain a Dynamic Cache which will have a flag to lock/unlock a particular piece of (new)code. For all such…
Saum
  • 35
  • 1
  • 8
1
2 3 4