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)

5
votes
3answers
172 views

Implementing common logic in base class

Background In the documentation of a project I'm working on I came across the following sentence which immediately triggered an alarm for me: when having several concrete classes that inherits ...
2
votes
3answers
121 views

Unit Testing and dependencies

I'm just learning how to do proper unit testing, and a lot of resources make reference to using explicit dependencies, ie dependencies that are passed into the constructor, to allow for easy ...
0
votes
1answer
45 views

Test logic with external data [duplicate]

I have a site programmed in PHP where I make more call to external server that return me big xml of data. For each record of the xml I have to make other external call to get other data. So my ...
2
votes
0answers
114 views

Testing a method that reads from standard input and outputs to standard output [migrated]

I have a method which reads lines from standard input and outputs them to standard output. In a JUnit test, how can I have it send standard input to the method and how can it make assertions about the ...
3
votes
4answers
179 views

Filling the gap between Conception and Unit Test

I am stuck trying to do TDD. I'd rather seek the counsel of others who have gone before rather than waste time with trial and error. QUESTION: What diagrams / exercises / development processes can ...
0
votes
0answers
19 views

How to handle karma/bower in a Symfony Bundle on github?

i am working on a Symfony Bundle that uses angular among other javascript deps. Now i want to unit-test my javascript code and i want to ship those tests as well. My initial idea was to add ...
2
votes
2answers
63 views

Value of unit testing property setters to check events [duplicate]

When coding in WPF with the MVVM pattern, it's common to see a lot of property get/set statements that raise an event, which can then be picked up by the UI layer. public string Address { ...
5
votes
3answers
408 views

Is Functional Programming a viable alternative to dependency injection patterns?

I have recently been reading a book entitled Functional Programming in C# and it occurs to me that the immutable and stateless nature of functional programming accomplishes similar outcomes to ...
1
vote
1answer
57 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 ...
0
votes
2answers
102 views

how does test-driven development prevent us from type errors?

I heard (from Robert C. Martin) an assertion that since dynamic languages don't have static typechecking, people should write unit tests to prevent us from type errors. I'm not sure if I'm following ...
0
votes
2answers
78 views

How to ensure a new Unit Test is for the correct Test Case? [duplicate]

When writing a unit test for a scenario believed to be already covered, ie, the first run of the test would be green, what is a good guideline to ensure that it is in fact testing the proper test ...
-1
votes
5answers
85 views

Skillset for unit-testing [closed]

I have two questions regarding this topic: How long does it take for you to create unit-tests? Take a project for a web-application, and you are working TDD. How long time does it take for you to ...
7
votes
4answers
1k views

Is it bad practice to make methods public solely for the sake of unit testing? [duplicate]

I have a class with a public method. It has other methods that 'assist' with the purpose of the public method. The public method must be tested. However, I also want to unit test the private methods. ...
1
vote
4answers
241 views

How to make one test depend on the results of another test?

Let's say there is a utility class that provides some common static methods used everywhere in your code by many other classes. How would you design your unit tests for the consumers of the utility ...
5
votes
3answers
179 views

How to use unit tests when using BDD?

I am trying to understand BDD. I've read some articles and as I understood BDD is "the next step" from TDD. I say that because I find both to be very similar, and as I could read in this article, BDD ...
5
votes
4answers
177 views

How to unit test correct implementation of an interface is used?

I have this problem with unit testing for years. Unit testing should test isolated units, that is, if we use interface/implementation vocabulary, it should test concrete implementation classes. Fine, ...
3
votes
1answer
160 views

Why the practice of writing unit tests in a different language isn't that popular?

When Microsoft released Visual Studio 2008, there was a thing they were talking a lot about at the conferences and in their online tutorials: the idea of writing the actual code in one language, and ...
1
vote
1answer
68 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 ...
4
votes
2answers
217 views

Is checking that a property doesn't throw an exception a valid unit test?

I'm writing tests for the following class: public class Foo : INotifyPropertyChanged { private int _failCount; private int _totalCount; public double FailRate { get { double ...
0
votes
3answers
99 views

Should all possible counter-cases be tested? [duplicate]

I'm currently trying to unit test a behavior which, in some very particular cases, returns B instead of A. It may depend on the value of 3 different attributes for example. How should I test this? ...
0
votes
1answer
92 views

Testing process on life critical systems [duplicate]

I currently work in web development - unit testing, functional testing are all good and really are part of what is considered being a professional developer. However, I also have a fear of flying and ...
1
vote
0answers
54 views

Unit testing Eloquent outside of Laravel

How can I unit test my Eloquent models when I'm using the ORM outside of Laravel? What I'm hoping to do it run tests on each model but somehow mock the database connection/query/builder(?) object. ...
5
votes
1answer
283 views

Should the expected value be hard-coded into the Assert

My own personal preference would be to use a variable, but maybe there are reasons against this? I haven't been able to find any resources that state the pros or cons of using one of these over the ...
6
votes
5answers
275 views

How should I unit test mathematical formulae?

I have a number of functions that are pretty close to the mathematical definition of a function. For example, a simplified version of one of these functions may look like: int function foo(int a, int ...
4
votes
6answers
127 views

How do you check that code has been covered automatically?

I am in the process of setting up a Bamboo server for some new projects for a push to TDD in a CI/CD workflow. Sure, unit testing is great, but only as log as it is there. Now this might be better ...
0
votes
6answers
184 views

Cheap implementations in fundamental TDD

This is a question concerning the fundamental approach of TDD, so the example below is as simple as possible which might make it seem a little useless; but of course the question applies to more ...
0
votes
2answers
53 views

How to add cases to large legacy code base project? [duplicate]

There is a legacy project full of C++ code. As a MFC GUI project, it contains lots of businesses logic out of control and beyond average level programmer to understand. To work on such GUI project, is ...
0
votes
1answer
77 views

MockRepository vs Test Database for Unit Testing

Before starting, this question is not the same as this one. Comming from a PHP background, my experience is in CakePHP, which is a framework that supports Unit Testing by setting up a local test ...
3
votes
1answer
121 views

How do you write tests for methods that interact with data in system files?

I'm trying to be proactive about writing an iOS app in a test-driven manner. However, I'm stumped as to how to test a method that is to interact with real system files. For those familiar with iOS, ...
0
votes
1answer
63 views

Beginner's UnitTests for MVP Presenter class

In my application, I have a user settings form with roughly 20 checkboxes and a few other controls. The checked state, enabled state and texts of these controls are bound to about 60 properties of the ...
1
vote
3answers
139 views

What does stubbing mean in programming?

I often hear the term stub, stub out somethings, stubs, ...etc. What does stubbing mean in programming, where the word come from? and in what contexts it can be used?(just examples)
5
votes
4answers
574 views

How to test a method which is not as much as a unit, because it is more of a 'orchestrator' / 'process' / 'controller' / 'coordination' class [duplicate]

I want to test a method which is not as much as a unit, because it is more of a 'orchestrator' / 'process' / 'controller' / 'coordination' class. This is the case: I have four unit tested classes: ...
6
votes
2answers
342 views

Small code, big test

I have this code in a controller of an MVC implementation: public void execute() { try { String path = userSelectsFile(); if ( path == null ) return; //Just returns ...
8
votes
2answers
341 views

How much logic can be put into a command? Or differently: What kind of logic is command pattern for?

I have been using the command pattern for quite some time but I'm never really sure how much logic I can actually put in the Execute method. My current implementation of the command pattern looks ...
0
votes
2answers
169 views

Which language has most advanced support for proof based programming? [closed]

By proof based programming, I mean, you can somehow prove the correctness of your program without testing. I heard that Ada has a feature called contract, I also heard that, if you can pass Haskell's ...
2
votes
2answers
352 views

should I test this public method

I have the following simple implementation: var VALIDATION_TYPES = { ERROR: 1, WARNING: 2 }; var validationRules = {}; this.addErrorRule = function (event, rule) { ...
2
votes
2answers
172 views

When testing is it OK to use a method of the subject to test another method of the subject? [duplicate]

I have two methods in the same helper class one that creates an image (method A) and one that compares two images (method B). I want to check the return of method A against an existing image. To do ...
1
vote
2answers
202 views

How to add rigor to my testing?

I work on a small/medium sized Java application. Over time, I've tried to ensure that the tests which I write are "good" tests, and that there's plenty of them. Hence I've been looking into various, ...
-1
votes
2answers
238 views

Scheduling a Jenkins job to only run integration test [closed]

My current company has a Jenkins/DotCi setup. Our current process for CI is when dev pushes to github, jenkins runs unit tests on all branches and reports back to us via email if the unit tests ...
10
votes
4answers
1k views

Is there any value in writing a unit test that is a subset of another test?

To give a slightly contrived example, let's say I want to test that a function returns two numbers, and that the first one is smaller than the second one: def test_length(): result = ...
0
votes
1answer
118 views

Testing - How to test if you are actually testing the code?

I was thinking about unit tests and code coverage, and I came up with this thought: It is possible to have 100% code coverage and not test 100% of your code. For example: function ...
0
votes
1answer
49 views

Testing - Test for Specific Paths?

When (unit) testing, is is bad to expect the code to use certain paths. For example, should I be testing for specifically "/build/static/public/css/", or just that server.cssPath has been set to a ...
12
votes
4answers
1k views

This way I'm writing this code is testable, but is there something wrong with it I'm missing?

I have an interface called IContext. For the purposes of this it doesn't really matter what's it does except the following: T GetService<T>(); What this method does is look at the current DI ...
1
vote
1answer
244 views

How to write unit tests for a piece of code that has a data context?

I am new to unit testing and using Microsoft's unit testing library for following piece of code. When I execute the code normally it executes fine, however when I run unit test written for this code I ...
3
votes
1answer
134 views

Unit testing a template class after refactoring

I am cleaning up my code by way of removing duplicates, and found two classes that were almost identical, out of 55 lines, only a single predicate in an if statement differed between them. Both ...
3
votes
1answer
84 views

Where does test fixture code fit in?

This is an unusual question since I don't believe it lends itself to typical software development practices but I hope you can prove me wrong. In MATLAB, my team have created several signal ...
7
votes
2answers
307 views

How do I unit test a heuristic algorithm?

Say we have our route finding algorithm: def myHeuristicTSP(graph): /*implementation*/ return route Now we want to unit test this: class TestMyHeuristicTSP: def ...
3
votes
0answers
116 views

How to test network connectivity API using TDD?

I'm currently trying to add TDD on my workflow. I fail to create tests where I can easily test a library that requires remote connections. More precise, my program uses snmp4j library. Currently I'm ...
-1
votes
1answer
69 views

Starting a big application with unit testing [closed]

I am learning test driven develeopment and read some books about TDD. I learned rules of unit testing. How can I write unit test, how can I select test method names, Act, Assert, Action and like this. ...
0
votes
2answers
246 views

Workaround for unit testing Core Data in Swift

I am still pretty new to programming, but my first app was recently approved and is now for sale on the App Store. My app uses Core Data and is written in Swift. After some initial difficulties, I ...