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)

-1
votes
0answers
39 views

CRAP index (56) in Web Scraper Engine

I am working on a Web Scraper for the first time using Test Driven Development, however I have caught myself into a huge CRAP (Change Risk Anti-Patterns) index (56) and I can not seem to find a ...
2
votes
1answer
43 views

Sampling with weighted probabilities

In an exam question I need to output some numbers self.random_nums with a certain probability self.probabilities: I have ...
-2
votes
0answers
32 views

Can empty test in c# be clean code? [closed]

Let's say I have a class with following functional performance test ...
2
votes
1answer
21 views

Testing a socket-based application

Summary: How can I best write tests that override socket-based communication for a library, capturing what is sent over the socket, and simulating responses based on what is sent? Details I'm adding ...
5
votes
2answers
54 views

Recursive binary search implementation in Python

I have this (recursive) binary search implementation in Python, and I want you to criticize every aspect of it. It is a naive implementation, (drilling the basics and stuff), but, I want you to ...
0
votes
0answers
19 views

Validate if time is valid including tests

So, I'm working on a method to validate if given time(s) are valid. In most cases, the input comes from the user. I'm not exactly sure on a few points: Readability Integrity Performance I'm also ...
5
votes
1answer
62 views

Unit test if an event has been raised or not

Given the following event dispatcher code ...
8
votes
2answers
113 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 ...
4
votes
1answer
40 views

String concatenation comparisons

For some time, JavaScript string concatenation could be optimised by join()ing an array of strings, instead of +ing them ...
4
votes
1answer
52 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
128 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
108 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
109 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
588 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
95 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
96 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
46 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
36 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
98 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 ...
14
votes
2answers
236 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
146 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
135 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
62 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
27 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
91 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
727 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
48 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
83 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
62 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
60 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
127 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
344 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
108 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
119 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
477 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
81 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
181 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
51 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
238 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
353 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
48 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
134 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
40 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
53 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
56 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
55 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
92 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: ...