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 (1)

-2
votes
0answers
19 views

Mock Unit test with Service locator [on hold]

I am new to Unit testing, so can someone please guide me how to implement Mock unit testing for my code. HomeController ...
3
votes
1answer
39 views

Unit test if an event has been raised or not

Given the following event dispatcher code ...
8
votes
2answers
94 views

Next number with the same sum of digits

I recently came across a email bot that would give you random problems to solve. Here is the problem. Please write a function in python which receives a natural decimal N-digit number (1 to 15 ...
3
votes
1answer
36 views

String concatenation comparisons

For some time, JavaScript string concatenation could be optimised by join()ing an array of strings, instead of +ing them ...
-2
votes
0answers
28 views
4
votes
1answer
45 views

Simple Ruby program to model a prepaid transit card system

I have written a simple Ruby program to model a transit card system which aims to address the following user stories. I wanted to see whether I could get any feedback on it. My main interest is ...
6
votes
4answers
123 views

Unit Testing the Duck

I recently reinstated the unit tests in Rubberduck. Previously, our parser was a synchronous parser, with everything running in sequence, and we could just request a parse result. Now, however, it ...
6
votes
1answer
98 views

Creates a menu and sidebar in Google Spreadsheets

In an effort to make my code more testable, I'm trying to make use of constructors and prototypes. Here is a working Google Apps Script (GAS) for creating a new submenu under the Addon main menu in a ...
8
votes
2answers
107 views

Number to Roman numerals

I've been working on numerals conversion lately. Now the JavaScript course I'm following asked me to do something similar for Roman numerals. To keep things fresh and given the amount of test-cases ...
7
votes
2answers
582 views

Simple DateTime abstraction

Some of my tests require that I need to test the date time results (like time stamps etc.). In order to be able to test the date time string I created a simple ...
1
vote
2answers
94 views

Check if a word is before another

Let's consider a method like this: public bool IsWordABeforeWordB(string Text, string WordA, string WordB) { ... } By Word ...
2
votes
0answers
94 views

ASP.NET MVC with automatic testing (follow up)

This is a follow-up of this question regarding MVC application architecture fit for automatic testing. I have rewritten the DI code based on the answer provided there and also created some tests to ...
4
votes
1answer
44 views

This function for populating the attributes of a class, using a DB model and REST API

Recently, I've been trying to transform my code to be more OO and adhere to SOLID principles. I also have been trying to get into the habit of making my code more testable and have been trying to ...
2
votes
0answers
28 views

Unit Testing With Dependency Injection and MOQ

I'm just learning how dependency injection and mocking work, but I'd like some feedback on how I'm setting up a couple of tests. I can get them to pass, but I'm not sure this is all I need. This is ...
3
votes
0answers
28 views

CIDR Notation parser

I created the following code to better understand CIDR notation. Also to learn some of the Stream features in Java8. I posted my unit tests too. I'm interested in ways it might be improved ...
1
vote
1answer
84 views

ASP.NET MVC application architecture fit for Unit Testing with Mocking

I am trying to learn how to professionally work with Unit Testing, so I have refactored a medium sized project of mine (a sort of article aggregator that also does some ...
13
votes
2answers
226 views

All your bases are belong to Dijkstra

CATS, willing to get a hold of all the bases, asked Dijkstra to give him a hand designing the most powerful algorithm to reach all bases with the least distance travelled. I tried to implement ...
5
votes
1answer
144 views

Geocoding hook for a TYPO3 extension

I'm currently developing a TYPO3 Extension in PHP and developed a Hook. TYPO3 has the concept of Hooks where you can execute your own code as specific points. As defined in our definition of done, we ...
5
votes
4answers
133 views

Writing to a newly created file, with support for unit testing

When now increasingly making code unit testable, I notice that code gets bloated, only to get dependencies out. A simple file operation, like saving a file, and, if a file with the name already ...
3
votes
1answer
54 views

Unit Testing Express Middleware That Verifies Auth Tokens

I am writing an Express middleware component that'll run on Node 4, which has limited ES2015 support. The fundamental purpose of this component is to verify JSON web tokens, using the jsonwebtoken ...
2
votes
1answer
26 views

Converting fraction notation in strings to a Rational data type

I've been messing around with a RationalInt type, using a simple int-based structure for the time being. I've created code to ...
9
votes
1answer
83 views

Tokenize s-expressions in Rust

I'm writing an s-expression tokenizer in Rust. I have the following code written, but it is not idiomatic Rust - it is quite ugly. TokenizerI is simply an ...
11
votes
4answers
720 views

Using reflection in a test to check if a private variable is really null after a function, is this okay?

I am using reflection to check if a private variable is set to null after the logout function. This is needed because the getUser function will always attempt to set and return an user if no user is ...
3
votes
1answer
47 views

Test cases for an elevator simulator

I'm trying to test an elevator simulator program that runs in the console and requires user interaction. At the moment, my tests look like this: ...
0
votes
1answer
72 views

Angular directive test

I'm learning how to write tests in Angular (these are my first tests in general). There are a lot of tutorials out there but each one of them has a different approach. I'm a bit confused if I'm doing ...
2
votes
2answers
61 views

Sales Tax problem (new version)

I was told that this version is too simple, that need something more complex. I added Entity Framework. Here my code: ...
1
vote
0answers
52 views

Integration tests for a repository with the help of AutoFixture

I find it hard to do integration tests for a repository and very time consuming. Things I think about when creating integration tests for a repository: Should I skip them? Should I create an in ...
14
votes
2answers
125 views

Builder pattern for users in document database

I'm attempting to make a builder pattern that makes sense and is practical for storing user data in a flexible way in a document database. The DB I chose is MongoDB, and I'm using its Java API ...
8
votes
4answers
341 views

Implementing common fraction using TDD

Recently, during the interview, I was asked to implement basic arithmetic operations with common fractions using TDD. The task is fairly simple, but I was nervous so I did not do too well. :) Later on ...
1
vote
0answers
89 views

REST service API using Python Bottle

I am working on a sample REST service to study testing related aspects using the Python Bottle framework. I read a lot about REST but I do not have a lot of practical experience designing RESTful APIs ...
6
votes
2answers
115 views

String Calculator Kata in Scala

This is my solution of string calulator kata in scala(i'm new of tdd). I'd like a general review of this. String Calculator Create a simple String calculator with a method int Add(string ...
1
vote
1answer
380 views

Entity Framework 7 In Memory Database - Unit Testing using xUnit

I'm using EF7 with In-Memory database and xUnit for repository testing. I'd like to know if it's a good practice initializing the database in this manner for reuse it in every test method, ...
5
votes
2answers
80 views

Unit test for a function that adds users

I'm new to unit testing and I'm curious if anyone can see any problems with my approach below. Basically I want to test the Add function. To do this I am creating ...
5
votes
2answers
172 views

Checking if text is NOT displayed

I'm currently writing unit tests in Selenium (C#). I need to do two things in this particular test: Check if 2 errors (with html container) are displayed and check if another (given) error is not ...
5
votes
1answer
48 views

Test whether target string is substring of source string

The code is self-explanatory. It has \$O(n)\$ complexity, and it tells whether a given string is the substring of the source string. Are there any cases where this algorithm fails? Is there anything ...
2
votes
3answers
204 views

Solving for equilibrium index in an array

I did a sample on Codility and finished the test task. The problem description is very short: The equilibrium index of a sequence is an index such that the sum of elements at lower indexes is ...
7
votes
3answers
345 views

Implementing xrange

I wanted to learn about Iterable and Iterators and hence thought about getting my hands dirty rather than reading theory and ...
2
votes
0answers
46 views

Are AVL trees equal? - revision 3

The original question Given two binary trees, return true if they are structurally identical, and false otherwise. Are AVL trees equal? Are AVL trees equal? - revision 2 This revision on ...
5
votes
3answers
131 views

ASP MVC Controller Unit Test

So I've been writing a unit test using Rhino Mocks to a controller in my ASP MVC application. The test passes, but I'm interested in your opinion and if there's something I should be doing differently ...
6
votes
0answers
35 views

Generate a URL, shorten it, insert it in a tex file and compile those tex files

I have written a NodeJS module and its tests to generate a URL, shorten it with Bitly, insert the short link in a tex file, compile these tex files to PDF and then merge them into one. The code is ...
1
vote
1answer
52 views

Are AVL trees equal? - revision 2

Revision 1. This revision on GitHub In addition to the solution itself, I wrote tests for all the possible cases. It seems you have verified all execution paths are covered. You are ...
4
votes
1answer
54 views

Hacky Haskell monadic testing

Edit for posterity: The library you're looking for is Hspec. I recently started writing Haskell tests with HUnit. My general setup looks something like this: ...
3
votes
1answer
1k views

EF Generic Repository + Unit of Work pattern with support for Async

I'm working on a generic repository using EF 6 code first and trying to following the Unit of Work pattern. Unity is being used to inject my repositories, and I'm trying to get everything supporting ...
2
votes
2answers
53 views

C++ Minimalistic Unit Testing Library

I was looking for a unit testing library for C++, and I found many. Unfortunately, I decided I didn't want to use any of them. I decided to make my own. This is the result. I made heavy use of the ...
5
votes
1answer
91 views

An attempt on unit testing in C++

I have no much experience with C++, so it is about time to start actually doing something about it. All in all, I coded this tiny unit test library: assert.h: ...
4
votes
1answer
55 views

Unit Testing and good use of matchers

I been having discussion with colleagues recently about good use of matchers. Consider the following sample: ...
10
votes
1answer
109 views

Find all the primes less or equal than N

This is not a novel interview problem. But I want to address it with the following points: Implement the algorithm with Object-Oriented Design principles in mind. Optimize the solution, if there are ...
3
votes
1answer
75 views

Bot that selects web reviews based on spreadsheet entries

In my program, I prompt the user to enter a range of cities (in a spreadsheet), and then a range of review scores, and then make some decisions based on what the user has entered. Since the handling ...
0
votes
1answer
52 views

Basic sign-up method, testable and with try/catch [closed]

I am learning how to implement testing and try/catch statements into my code. I have a Laravel application with the following ...
7
votes
1answer
202 views

Are AVL trees equal?

I was inspired by this answer and decided to implement an AVL tree with the methods equals and hashCode as if I was asked to do ...