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

-3
votes
0answers
21 views

How should this code be unit tested? [on hold]

I have some code that I have some end-to-end tests written for, but am unsure if this code needs to be unit tested and what those tests should look like. To try to be clear, I don't expect an answer ...
4
votes
2answers
226 views

Longest substring with unique characters

Find the length of the longest substring without repeating characters Any comments on my code? ...
3
votes
2answers
48 views

Resource caching in Java with soft references

I'd like to cache some heavy resources locally. The goal of this implementation is to have be able to load resources for an unknown amount of time and then keep them in memory and finally evict them ...
2
votes
1answer
13 views

Simplified doctest

The doctest module seemed easy to implement so I decided to write a simpler version of it. my_doctest.py ...
7
votes
2answers
230 views

A (late) Simple Calculator

As I was looking through my past questions, I noticed my really old calculator question (here and here). Considering it looked like a huge mess, I decided to rewrite it. Coincidentally, the April 2015 ...
5
votes
3answers
128 views

Understanding my permalink service tests

I started writing unit tests cases recently. For now, I created only "perfect case" where there is no error. However, the test seems to me difficult to maintain and difficult to understand. How can I ...
9
votes
1answer
181 views

Rendering an HTML form based on a specification in a string

Here's a brief explanation of my method: Provide a string and parse it to HTML code respecting a specific format the accepted format is : For dropdown menu : Test DropDown~Select:Options1; ...
3
votes
1answer
43 views

Integer ID pool

I would really appreciate some feedback on the code I wrote to solve the following problem: Design an IdManager. IdManager manages a pool of integer ids. (from 1 to n). It should provide ...
5
votes
0answers
43 views

Improving a Java 8 unit test with Generics to be more readable and usable

Use Case I have a service that does processing of records from multiple third-party feeds. The steps are generally identical for each feed, but each feed is populated in a different location on an ...
5
votes
3answers
137 views

Random letter test

My first test (randomUpperCaseLetter) checks if the returned random letter is an uppercase ASCII one. The second one (...
1
vote
1answer
72 views

Accessing argparse arguments from the class

I have the following sample code running unit tests: ...
3
votes
0answers
53 views

Is this test sane? I may have re-invented the wheel on how to test that a method does not block

I have an Android service which must offload a task to a different thread but schedule the response callback unto the calling thread. After much thinking I came up with this code: ...
7
votes
3answers
103 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
102 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 ...
1
vote
1answer
24 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
61 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
54 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
57 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
228 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
129 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
72 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
432 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
76 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
40 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
76 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
36 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
81 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
41 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
470 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
98 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
246 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
298 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
73 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
172 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
760 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
59 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
113 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
77 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
90 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
198 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
127 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
47 views

Computing a list from Graphite JSON

I had a simple function. ...
7
votes
2answers
387 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
72 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
41 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
67 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
217 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
169 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 ...