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

0
votes
0answers
7 views

This TDD code seems noisy

This is my very-first-ever run at TDD. How did I do? In keeping with Uncle Bob's Three Rules, I wrote every test first, starting in order from the top down as you see here (below). Here's the ...
5
votes
1answer
72 views

Hard-to-test 3 Tier Architecture

I'm having trouble testing some code. It's laid out in such a way that the business logic relies on the persistence layer. Some classes require that an object be saved to a database. Some classes ...
5
votes
2answers
183 views

Create better Unit test

Question: Is there anything you could do in order to improve the test? I am using Spring Framework 4, Hibernate 4, JUnit 4. All DAO unit tests inherit from TestDaoSetup class: ...
7
votes
2answers
78 views

Test string if numeric

I want to implement the following function: ...
4
votes
1answer
59 views

Loop cleanly through different classes

If I have a number of different classes which manage certain tests. At the moment I have to launch each test individually which results in a lot of if statements. ...
10
votes
2answers
91 views

Unit tests for an argument-checking class

I am wondering if my current unit tests could be written better, I am most interested in whether it is possible to make the code look more concise, as currently it a boiler-plated mess. I have full ...
15
votes
3answers
437 views

Writing better JUnit tests

I am using Spring Framework, Hibernate and JUnit. I am testing persisting of a UserEntity. The UserEntity has the following associations: ManyToMany - City ManyToMany - ActivityCategory ManyToOne ...
10
votes
1answer
109 views

Markup calculator application using MVC

I want to make sure that the code is correct in terms of its design, code correctness, best practices & Junit testing. The complete description is given below: Functioning of the app quickly ...
12
votes
3answers
184 views

Trading Card Game's Hand class and tests

As part of a Trading Card Game, I have created a Hand that will need to hold all cards that a player currently has in his hand. The code is built using Java 8. The ...
9
votes
1answer
102 views

Automatically run doctest every time program is run

I would like this to happen every time I run a program from the command line. Is my approach Pythonic? I'm interested to know whether there is any problem with readability or correctness. Any general ...
3
votes
1answer
80 views

Unnecessary unit test?

I have this method in my service layer ...
7
votes
3answers
115 views

Unit tests: to cast or not to cast?

Suppose the following example unit test for an ASP.NET MVC controller: ...
4
votes
2answers
62 views

Server side validations and unit testing in MVP

We are following passive controller approach and when user clicks on submit, server side validations are fired. There are many other fields on the screen that needs to be validated. I would like to ...
3
votes
1answer
64 views

Testing async API calls using Jasmine 2.0

I'm upgrading my project from YouTube's V2 API to their V3 API. I'm also taking the time to upgrade to Jasmine 2.0 since I already need to look at my test cases. Here's a couple of test cases and the ...
10
votes
4answers
304 views

Schedule class (exercise for test driven development)

Schedule is a simple class that could be used in program to manage when a task should be repeated (a todo list, for example). Its constructor requires a start date and an optional end date. Then type ...
4
votes
1answer
36 views

Ranking a variant array with variable dimensions

I'm doing VBA macros and need to use Arrays of values extensively. After the below help from @TonyDallimore in StackOverflow, I've decided to use nested variant arrays. VBA chrashes when trying to ...
7
votes
3answers
142 views

Refactoring method to make it unit testing friendly

I have a completed application which I'm trying to write unit tests for (Yeah I know, talk about bad practices) I have the following class here ...
4
votes
1answer
108 views

Am I over-engineering?

So I just jumped to a new project, which uses activerecord pattern. It's a subscription service website. I have the following User object that extends a framework specific ORM object. ...
11
votes
3answers
1k views

Sudoku Solver: what are good ways to avoid the deepcopy?

In an effort to teach myself some python and programming in general I made a Sudoku Solver (as many others have done before me from what I can tell). The one thing that bugs me a little is my use of ...
0
votes
2answers
67 views

Unit Testing Datalayer written in ADO.net

I have datalayer code as below which is implementing an interface as: Note: I have hand written this code on Notepad so it may contain some typo errors, which you can gracefully ignore. I am ...
9
votes
2answers
237 views

Using a Pythonesque range() generator function with the Java foreach loop

Now that we have the nice new foreach loop in Java, the old-style loop looks ugly be comparison. I like the way Python has a range() generator that allows the ...
9
votes
1answer
117 views

Do my unit tests follow best practices?

I've watched quite a few videos and read a couple of articles on unit testing and I've tried my best to make this test case as good as possible. In which areas can it still be improved? I should ...
3
votes
1answer
144 views

Unit tests using C#, Moq, AutoFixture, FluentAssertions

Could you give any suggestion on the following unit tests? How to make it more readable, maintainable and trustworthy. If it is not a problem - post some code with the suggestions. ...
5
votes
2answers
79 views

First time BDD: Testing the same things in both acceptance and unit tests

I just tried BDD for the first time and implemented a simple Semantic Versioning Bumper in Python. The class takes a version string in the format of major.minor.patch (i.e. 3.2.2, where major=3, ...
1
vote
1answer
89 views

Structuring unit tests

I have settled with this type of structuring of unit tests. Basic idea is that there is a base test class for the tested class, and a subclass for every tested method. They use the mocks and ...
4
votes
2answers
75 views

Implement strtod parsing

In this comment the OP wrote, I am a newbie so i would like to know how would i parse the negetive numbers/arguments ? In this answer @200_success showed an implementation using the strtod ...
1
vote
1answer
184 views

Unit testing - test class inheritance vs single test class [closed]

Which unit testing approach and WHY do you prefer? Inheritance-driven-testing ...
17
votes
4answers
1k views

Just a lowly counter that turned out to be surprisingly complicated

While writing this review, I saw a need for a Counter object similar to Python's. It seemed like it would be easy to write such a class, but it turned out to be ...
3
votes
2answers
111 views

My first model RSpec

This is my first model RSpec test: ...
6
votes
2answers
94 views

Create and destroy object in Unit Test

I have some doubt when I should create an object in an Unit Test when the object needs to be stopped cleanly. Usecase: I have a class ComplexClass which has 3 functions: Start(): starts a Thread ...
10
votes
1answer
224 views

Writing and reading of a custom binary protocol

I'm currently trying to develop some code that will handle parsing and building of a custom binary protocol. The protocol itself is still fairly fluid but the basic core features are decided. These ...
3
votes
2answers
80 views

Read Lines From IIS Log

The purpose of this class is to read an IIS log (or multiple ones). One thing to note is that the columns can differ based on settings in IIS. So a couple of concerns that I have: Is The ILogReader ...
3
votes
0answers
30 views

Doctest for a method that expects a filename parameter [closed]

This method gets a file_name string as an argument. What if I don't want to pass a file_name in the doctest? I just want to ...
6
votes
1answer
120 views

How should I structure my Unit tests for minimal Asserts?

I always see comments about how a Unit Test should only be testing one piece of functionality. For the most part, I definitely agree with that assessment. However, I'm working on testing a method ...
7
votes
3answers
768 views

Simple Hello World with unit tests

This is a simple hello world sample project used for instruction. I'm just looking for general comments on the approach and design. AdvancedHelloWorldTest.java ...
7
votes
4answers
392 views

Testing code with Debug.Assert

I have a small little function in a VB6 codebase: ...
2
votes
1answer
137 views

Where to put common method used in controllers that calls service layer?

I have an asp.net mvc5 web application using the repository pattern, and I have several controllers that need to call my _loggingService (queries audit logs) to get the last updated information for ...
7
votes
1answer
105 views

Are these the right type of unit tests to write?

Trying to get an understanding of proper unit testing, I've read up quite a bit and found myself writing tests like the ones that follow. Based on "best practices" etc., how am I doing as far as ...
7
votes
1answer
189 views

Measuring a method executing time

I have been playing around with some improvements to some sort algorithms like Selection Sort and Merge Sort and I ended up needing some sort of measurement to check if my versions were any faster ...
4
votes
1answer
131 views

PHP wrapper around an API - best practices

Here's a PHP wrapper around a public OAuth2 REST API. I would love to hear your thoughts and comments. Testing was a bit frustrating since I tried for my first time. Not sure if I have done the ...
1
vote
1answer
79 views

Is this a good approach to unit testing?

I'm relatively new to unit testing and having gone through quite a bit of pain I was starting to feel pretty good about my tests. The problem is, now I have a nice set of green ticks I'm also ...
1
vote
1answer
94 views

Testing mapping code

Obviously, you have to test mapping code somehow, even (or especially) if you use AutoMapper. Is there any way to make it less verbose? ...
3
votes
0answers
39 views

Are these CppUnit tests OK?

I wrote a CppUnit test suite to unit-test the code that I posted here which is a single routine that proposes how a Lua expression could be auto-completed. What do you think? I appreciate all the ...
2
votes
1answer
35 views

Multiple Services and Test Setup

Class To Test Some methods hidden for clarity ...
21
votes
3answers
981 views

Code indentation for declaring inputs/outputs in an array

I'm writing a list of inputs and outputs for to be compared in unit tests. ...
4
votes
1answer
117 views

Configuring Constructor Parameters and Unit Testing

Currently working on writing out some test for an iOS enterprise application. My concern is in this set up of my overloaded constructor. ...
7
votes
2answers
125 views

Am I missing any unit tests in this base class for testing equality?

I've created this abstract base class for testing the Equals method. The basic idea is that derived class implements methods to get: the primary test instance, ...
8
votes
2answers
104 views

Testing classes

I'm just getting into testing and wanted to see if someone can tell me if I'm writing tests correctly. I'm using C#, NUnit, & Should. This is the class I'm testing: ...
6
votes
1answer
537 views

Unit test best-practices in Python

I'm a Java/C coder getting started with some Python for a side-project. I've written some unit tests for a recent side-project I'm working on, but I have a sinking suspicion I'm just writing ...
3
votes
1answer
97 views

Python Fizz Buzz, Acceptance Unit test

OK, maybe crazy overkill and a little silly, but why not? Here's a Python FizzBuzz Acceptance Test: ...