Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
0
votes
0answers
13 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
247 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 ...
4
votes
4answers
168 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 ...
0
votes
0answers
10 views
iOS: Writing tests for blocks [migrated]
I am trying to write a test for a function that takes in a success and failure block. Here was my first attempt at a test:
- (void)testThatValidSearchProducesSearchResults
{
__block NSArray ...
3
votes
6answers
107 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
163 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 ...
-2
votes
0answers
34 views
What is tool of your choice for Javascript testing [closed]
Currently I'm workin with jQuery and use Qunit for testing, but it seems to me not optimal library for testing.
So what tools are you using for javascript testing?
0
votes
2answers
42 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
0answers
30 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
79 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
54 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
108 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
551 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:
...
5
votes
2answers
329 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
323 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
159 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
348 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
164 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
151 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
128 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
109 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
47 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
5answers
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
208 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
111 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
80 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
262 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 ...
2
votes
0answers
103 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
61 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
154 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 ...
3
votes
5answers
198 views
How do you unit test a function that clears properties?
I have a very common function that I have always unit tested in the same way, but I'm wondering if there is a better solution or if it's even possible a code smell is involved. It seems like a very ...
0
votes
0answers
41 views
Using a mock Spring bean [closed]
I m actually introducting to unit testing with Junit and I am wondering if I m doing the things right.
In fact, I want to test a service in which I inject a repository (a Spring bean in my case with ...
2
votes
2answers
265 views
Unit testing and reality [closed]
I m actually studying Unit testing, reading some articles on the internet and trying to understand how it works exactly, but it's not very clear for me actually.
What should I test ?
I have seen ...
4
votes
3answers
142 views
Test Driven Development when the specifications change
These days, it's fairly common for me to be tasked to make a change that actually breaks the prior spec. I know that one of the major ideas behind TDD is to have a suite that verifies all your changes ...
1
vote
1answer
52 views
Java Unit testing multiple test cases in one test [duplicate]
Is it good practice to have multiple test cases in one test or should I always create one test for single test case in every situation even if it is redundant? Why?
5
votes
1answer
135 views
How do you unit-test code using graphs?
I am writing (recursive) code that is navigating a dependency graph looks for cycles or contradictions in the dependencies. However, I am not sure how to approach unit testing this. The problem is ...
0
votes
1answer
76 views
Can JUnit be used to test this project?
I currently have an interesting situation occurring with my code, and after hacking away at what turned out to be a dead end for the last two weeks, I'm here asking those smarter than I to educate me ...
4
votes
2answers
136 views
Separate code coverage reports for unit and integration tests, or one report for both?
Should there be a separate code coverage report for unit and integration tests, or one code coverage report for both?
The thinking behind this is that code coverage allows us to make sure that our ...
15
votes
3answers
1k views
How to test when arranging the data is too cumbersome?
I am writing a parser and as a part of that, I have an Expander class that "expands" single complex statement into multiple simple statements. For example, it would expand this:
x = 2 + 3 * a
...
1
vote
1answer
141 views
Unit test approaches other than test-first and test-last? And what about variants of them? [closed]
I'm wondering if there are other approaches, old or new, to writing unit tests, and how viable they are, other than the traditional and tdd unit testing approaches.
I know there is behavior-driven ...
1
vote
2answers
85 views
Should you mock key-value stores/aggregators
I've always been taught that your tests should run in isolation, and other than a db for ActiveRecord etc., your tests should not rely on any external software/services. e.g. I always mock my other ...
0
votes
2answers
57 views
Unit testing the variables passed to the view from the controller
Let's say I want to test a controller that gets some value from a service and then pass some of all of those values to the view.
Do you test that the view gets the result that the controller took ...
8
votes
5answers
1k views
Sharing development test cases (unit and development integration) with the QA (test) team?
The testing team (the so-called QA team in some organizations) insists that the development team should share their (the development team's) test cases with them. Their arguments are that the ...
9
votes
4answers
707 views
How to do Test Driven Development
I have just 2+ years of experience in application development. In those two years my approach towards development was as following
Analyze requirements
Identity Core component/Objects, Required ...
0
votes
3answers
149 views
What's the idea behind mocking data access in unit tests [duplicate]
I understand that you're not actually supposed to hit the database or disk when doing unit tests... Why is that?
Also, taking something like Moq, what is it actually supposed to mock and where? For ...
2
votes
1answer
287 views
2 questions about TDD
I'm just starting to get to grips with TDD, and I have 2 quick questions;
I'm assuming that if I were writing software for a software company, that TDD would work alongside the software design? i.e ...
1
vote
2answers
221 views
Mocking the context of application
We have a context of the application which is a static class named Holder containing several static properties initialized by objects that are used throughout the application.
All over the unit tests ...
5
votes
6answers
501 views
When should you start unit testing? (during which development stage?)
I'm currently learning about unit testing, specifically JUnit (with Java).
Searching the web I see many threads talking about why you should use it, what type of methods you should use it with but I ...
2
votes
2answers
139 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).
...