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

5
votes
1answer
35 views
6
votes
2answers
131 views

Testing quicksort user input

I am testing a quicksort implementation. Arrays of random size with random data are passed to quicksort and the return time is averaged out. The user is prompted to enter values for minimum length ...
5
votes
2answers
84 views

Unit Testing an AppInfo class

I have never written a unit test and I am really new to C#. I am attempting to test a method, am I testing for the right things here? The Method ...
2
votes
1answer
37 views

Unit-testing account transaction code

I'm playing with unit-testing in Ruby. There is a situation that I don't know if is good enough or if I am doing the wrong abstraction. I have two classes: ...
7
votes
1answer
59 views

JUnit extending abstract test class

I have been thinking quite some time and asked an StackOverflow question about extending abstract test classes, but I haven't been able to do it until now. I'll list my approach and then discuss some ...
6
votes
1answer
39 views

FuseMonsterAction implementation and unit tests

I'd like to get a general review on the following code, and I'll highlight an extra point below: ...
5
votes
2answers
49 views

Using the builder pattern to build mock objects and nested builders

No, this question has no roosting construction workers. I'm not sure if what I'm doing is a good use of the builder pattern or whether its a bastardization of what its intended purpose was. I'm ...
4
votes
2answers
68 views

Using shims to turn my integration tests into unit tests

I want to understand how to properly unit test a function such as this. The function doesn't return anything, but it does call other functions that themselves have already been unit tested. My ...
3
votes
1answer
60 views

Python Best Practices - File Validation and Unit Testing

I just started a new project which reads in a video file and splits it up into frames. I started by just throwing everything in the GUI, but decided I wanted to make this a more well designed program, ...
1
vote
1answer
25 views

Testing individual nodes launched by naught using supertest

The purpose: an express node.js server which can be launched using naught, with an integration test using supertest. Each worker naught runs will test itself on a unique port, and only if passes it ...
3
votes
2answers
579 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
82 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 ...
6
votes
2answers
201 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
86 views

Test string if numeric

I want to implement the following function: ...
4
votes
1answer
60 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
96 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
465 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
157 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
203 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 ...
10
votes
1answer
111 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
82 views

Unnecessary unit test?

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

Unit tests: to cast or not to cast?

Suppose the following example unit test for an ASP.NET MVC controller: ...
4
votes
2answers
68 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
106 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
313 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
38 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
154 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
113 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
89 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
284 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 ...
10
votes
1answer
127 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
212 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
84 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
100 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 ...
5
votes
2answers
104 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
209 views

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

Which unit testing approach and WHY do you prefer? Inheritance-driven-testing ...
18
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
125 views

My first model RSpec

This is my first model RSpec test: ...
6
votes
2answers
103 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
326 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
98 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
128 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 ...
8
votes
3answers
808 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
411 views

Testing code with Debug.Assert

I have a small little function in a VB6 codebase: ...
2
votes
1answer
199 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
118 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
237 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
165 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 ...