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

7
votes
3answers
84 views

Simple greeting program based with timezone offset

I made a simple set of functions that returns a greeting based on the current time, the user's timezone offset, and the user's level. For context I wrote this as a part of a larger chat bot ...
6
votes
4answers
79 views

Unit testing IValueConverter

I am just starting to implement unit testing into my project and familiarizing myself with NUnit. I have added unit tests for encryption/decryption methods that I have implemented, and am looking for ...
0
votes
1answer
64 views

Unit test failing on case sensitive string comparison [closed]

I'm currently writing some unit tests for my own BinarySearchTree class with Microsoft's unit testing framework in VS2013. The VS solution contains the project for ...
1
vote
1answer
22 views

Splitting a string basing myself on categories

I was thinking about splitting a string based on certain categories, for example alphabetic and numerical, lower and upper case, and even the 3 lines of the keyboard. I wrote a generic function for ...
3
votes
2answers
59 views

Using Mockito to verify that an object is saved

We've been reviewing some legacy code and have found differences in the preferred approach to how to write tests using Mockito. Both the following tests pass but which one is better and why? ...
-1
votes
1answer
36 views

Locker puzzle in Python

(Game: locker puzzle) A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted S1, opens every locker. ...
3
votes
1answer
47 views

Rspec - testing basic functionality - redundant testing?

Being pretty new to testing, I was wondering how many of these tests make sense. restaurants_controller_spec.rb ...
2
votes
1answer
223 views

How to test “verification flow” code? would you test this at all?

I want to write unit-test to my code. However, while writing it, it seems all I can verify is that one method or the other were called once. My class is a manager that execute verification flow. It ...
5
votes
2answers
120 views

Unit Tests for getting the first Monday of the month

I have an application that runs hourly, and I want to use it to also send an email at the start of the day of the first Monday of the month. I searched and found information to help me code what I ...
0
votes
0answers
56 views

Unit testing - Parsing data from the Weather Underground API

I'm writing unit tests for the first time. The tests are for my library on Github. I downloaded the JSON and stored it into a local file that looks like this: ...
10
votes
3answers
409 views

Data Access Layer code for MSSQL Databases

We use this class quite a bit for boilerplate / glue that allows web services and applications to call databases. This code is very important, and I'd like to ensure I'm getting the best performance ...
3
votes
1answer
60 views

Unit testing HTTP requests

I would like to unit test my web requests, so on top of my head I came up with the solution below. Since it seems to be working fine, I'm posting it on this site. Though it doesn't feel very dynamic, ...
1
vote
2answers
38 views

Counting length-2 substrings that are common to two strings at the same offset — Python

I solved the CodingBat task: Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", ...
4
votes
2answers
75 views

Method for gaining access to private members in JavaScript for testing purposes

When running unit tests in JavaScript it is often useful to gain access to private members. Previously I would add an extra snippet of code inside the class definition (or whatever one calls this in a ...
0
votes
0answers
33 views

Unit test for running a query, using Mockito

What's happening here is we are testing QueryRunner.RunQuery(ANBQuery q) The method calls methods of two other objects, ...
8
votes
1answer
69 views

Growing my own Tree (Structure)

Summary VB6 doesn't have a great selection of data structures to work with, so again I find myself creating my own. I have a need to dynamically generate a directory structure on the file system. The ...
2
votes
0answers
37 views

MS VS solution structure w.r.t. dependency injection unit tests?

Is the following MS VS solution structure and classes OK w.r.t. easy unit tests with dependency injection? Would your unit tests look similar? If you call the calculations below over a WPF module, ...
5
votes
3answers
224 views

Savings account class and test program

My code is complete. It runs properly and produces the correct output. I did calculations by hand to check and then ran the program and it gives me the same result. I just want a second opinion. Are ...
3
votes
2answers
90 views

Simple Factorial Interview Task

I did this code for an interview. Can you tell me how it looks? I didn't get the job, so I'm wondering what I could do better in my code. ...
8
votes
2answers
239 views

Unit Tests for a Fraction Class

As my first Java homework, I wrote a class to handle fractions. This Fraction class implements basic operations for the fractions (addition, subtraction, ...
8
votes
2answers
297 views

The only thing better than being unique

is being first and unique. Challenge: Write a program which finds the first non-repeated character in a string. Specifications: The first argument is a path to a file. The file contains ...
2
votes
1answer
60 views

Same setup for many properties in Moq

I'm trying to use Moq to mock a rather large set of interfaces in an object. I'm trying to capture the behavior of retaining a dirty flag when properties are set and I'm hoping there is a cleaner way ...
7
votes
5answers
170 views

Writing a testable standalone DLL without overcomplicating it

I've decided to challenge myself by writing a test standalone DLL with the objective of making all of its publicly-exposed objects able to be as intuitive and as simple-to-use as possible. I've ...
13
votes
4answers
717 views

Coin dispenser program

I've decided to go tech and learn a language. I have been reading Java for a week and here is my first attempt. I am making a habit to write JUnit test cases so that I start on correct path. Here is ...
2
votes
1answer
47 views

Designing unit tests for paramiko wrapper

Before I get to the question, let me note that I'm a trained scientist, not a programmer; I've done my best to self-teach what I've needed to know so far, but in the interest of making my code usable ...
5
votes
1answer
109 views

Fizzbuzz in Python

I'm new to Python and wondering what can be improved with the following super novice program - in terms of the solution and code style etc. test_fizzbuzz.py ...
3
votes
1answer
69 views

Testing input validation and an AJAX request with Javascript and QUnit

I have a simple web page. The user enters the name and rank of a soldier and hits submit. If the input is invalid, an appropriate error message gets displayed. Otherwise, it adds the soldier to a ...
2
votes
1answer
31 views

Implement test which tries function with diferent params and expected results

What could I improve in the following code? The goal is to test a function againts a table of input parameters and compare to some expected results with some tolerance (as there are random variables ...
2
votes
1answer
78 views

Sudoku validator

I've decided to learn some more Haskell writing a Sudoku validator, the function checkSudoku outputs True if the Sudoku is valid and False if it is not. I did not ...
3
votes
2answers
156 views

Radix sort with integer divisions

Here's a perhaps naive but simple implementation of Radix sort in Java. It works with any radix, and both positive and negative numbers. ...
3
votes
2answers
102 views

Titleize words in a sentence but with some conditions

Below is the code I have written to capitalize all the words of a sentence except if The words belong to the littleWords list. The word would be capitalized if it's the first word of the sentence ...
1
vote
1answer
39 views

Computing a list from Graphite JSON

I had a simple function. ...
7
votes
2answers
367 views

Unit Testing Search and Sort method(s)

I just decided to write a unit test, and see how to do it. This is my unit test: ...
4
votes
1answer
68 views

Tested cartesian plane utility

I am starting to explore automated testing of code, so I decided to write some trivial code about the cartesian plane and test it. I am particularly interested in automated testing conventions and ...
0
votes
2answers
40 views

Testing a simple guard clause in isolation

I’m using decorator objects in a Rails app so that I don’t have to do nil? checks in views. Everything is working nicely and it’s easy to test, but I’m suspicious ...
7
votes
1answer
63 views

Unit test for Unique Position Point

Here is one of my msTest Unit Tests and possibly one of the worst "looking" tests. ...
5
votes
2answers
170 views

Unit testing a click event with asynchronous content

I'm writing unit tests for a web application that has quite a lot of UI interactions. I would like some feedback regarding on how to handle click events with asynchronous code. My goal here is to ...
5
votes
1answer
55 views

Unit Testing Bejeweled Wilds

I created a pretty complex algorithm for calculating matches on a Bejeweled board that kept track of matches involving wilds. After doing some in-game testing, I found quite a few bugs that needed to ...
5
votes
2answers
147 views

Stack data structure unit testing

I have this contract: public interface Stack<T> { void push(T object); T pop(); int size(); } I am curious what you think about my test of the ...
2
votes
1answer
74 views

Calculating Euclidean distance and performing unit-testing

The method creates a link, an edge between two nodes, and calculates the Euclidean distance. I'm testing that after linking, the link does indeed exist, and that the distance is correct. I've used ...
2
votes
2answers
83 views

Require config file in class

I want to use the variables that have been declared in a config.php file in a class for testing. I am not sure if this is the right way like I have done it. I have a configuration file, config.php: ...
4
votes
1answer
68 views

TDD and use case: cook dish with substitutions

This is code for a class that takes available ingredients and returns left over ingredients after making a dish. Cesars: 2 carrot 4 ice burg 1 chicken 1 beans Russian: 2 carrots 2 beans 2 chicken ...
2
votes
1answer
154 views

UnitTesting: Is this TestCase overkill?

Is this Test Case overkill? I am new to Unit Testing so I am learning and I'd love to hear your opinion about it. ...
0
votes
0answers
43 views

Designing entities, use cases and repository

I'm developing an Android application which would remotely connect to an insurance database and perform some basic CRUD operations and I'd like to learn how to keep clean app's architecture from ...
5
votes
0answers
70 views

Mucheck - a mutation analysis tool for Haskell programs

We have been working on a mutation analysis tool for Haskell tests called MuCheck. It accepts any Haskell source file, and a function name to mutate, applies a defined set of mutation operators on it, ...
4
votes
2answers
119 views

Credit card checking

I am practicing test-driven development in Python. Feedback about both the tests and the code is appreciated. I'm using luhn algorithm and regex to check credit card numbers for validity. Here are ...
4
votes
1answer
48 views

Test many sorting algorithms using Python and Nose

I'm trying to learn how to build a good test suite, using simple sorting as an example. Particularly, I am using Nose to generate all the tests based on a simple list of lists, where each sublist is a ...
3
votes
1answer
96 views

Filtering with multiple inclusion and exclusion patterns

I have a requirement to be able to filter a list of strings by both inclusion and exclusion patterns (using fnmatch-style wildcards), of which there can be many. ...
10
votes
2answers
105 views

Karate Chop Kata

I had some time to kill today, and I found the Karate Chop Kata. Specification: Write a binary chop method that takes an integer search target and a sorted array of integers. It should ...
10
votes
1answer
76 views

Even more extensible and testable BuzzFizz

Inspired by Extensible and testable FizzBuzz I have decided to write my own implementation, partially based on my own answer and on the other answers. First a warning to all of you: Never make such ...