Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
3
votes
2answers
17 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
25 views
Unit testing - test class inheritance vs single test class [on hold]
Which unit testing approach and WHY do you prefer?
Inheritance-driven-testing
public class GivenSynchronizedDataLink : TestBase
{
internal SynchronizedDataLink Subject { get; private set; }
...
15
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 surprisingly complicated.
...
2
votes
0answers
14 views
My first model RSpec
This is my first model RSpec test:
require 'spec_helper'
describe CashFlow do
context 'DB Fields' do
it { should have_db_column :amount_cents }
it { should have_db_column :amount_currency ...
6
votes
2answers
63 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
...
3
votes
2answers
44 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 wrap a simple string as a file and get the pseudo file_name, then pass ...
5
votes
1answer
89 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 ...
6
votes
3answers
697 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
/**
* AdvancedHelloWorldTest.java
...
7
votes
4answers
348 views
Testing code with Debug.Assert
I have a small little function in a VB6 codebase:
Public Function GetEquivalentCode(Optional ByVal code As String) As String
If IsMissing(code) Or code = vbNullString Then code = m_GlobalCode
...
1
vote
1answer
79 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
77 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
117 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
83 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 ...
1
vote
1answer
75 views
Is this a good approach to unit testing?
I'm relatively new to unit testing and having gone through quite a bit of pain I was starting to feel pretty good about my tests. The problem is, now I have a nice set of green ticks I'm also ...
1
vote
1answer
67 views
Testing mapping code
Obviously, you have to test mapping code somehow, even (or especially) if you use AutoMapper. Is there any way to make it less verbose?
[Test]
public void Map_Always_SetsSimpleProperties()
{
var ...
2
votes
0answers
33 views
Are these CppUnit tests OK?
I wrote a CppUnit test suite to unit-test the code that I posted here which is a single routine that proposes how a Lua expression could be auto-completed. What do you think? I appreciate all the ...
2
votes
1answer
32 views
Multiple Services and Test Setup
Class To Test
Some methods hidden for clarity
namespace RiPS.Infrastructure.UA
{
public class UAWorkflowManager
{
private readonly IContextIOAPI _api;
private readonly ...
3
votes
1answer
74 views
Configuring Constructor Parameters and Unit Testing
Currently working on writing out some test for an iOS enterprise application. My concern is in this set up of my overloaded constructor.
- (id)init
{
CRMHttpClient *client = [CRMHttpClient ...
7
votes
2answers
81 views
Am I missing any unit tests in this base class for testing equality?
I've created this abstract base class for testing the Equals method.
The basic idea is that derived class implements methods to get:
the primary test instance, and
a list of unequal instances ...
8
votes
2answers
90 views
Testing classes
I'm just getting into testing and wanted to see if someone can tell me if I'm writing tests correctly. I'm using C#, NUnit, & Should.
This is the class I'm testing:
using System;
using ...
6
votes
1answer
271 views
Unit test best-practices in Python
I'm a Java/C coder getting started with some Python for a side-project. I've written some unit tests for a recent side-project I'm working on, but I have a sinking suspicion I'm just writing ...
3
votes
1answer
61 views
Python Fizz Buzz, Acceptance Unit test
OK, maybe crazy overkill and a little silly, but why not? Here's a Python FizzBuzz Acceptance Test:
import unittest
from fizzbuzzmodule import fizzbuzz
class ...
5
votes
1answer
108 views
Does this FizzBuzz code correctly follow SRP and unit-testing?
This is a code for FizzBuzz. I have also hosted in on my github
FizzChecker Tests
[TestClass]
public class FizzChecker_Tests
{
IFizzChecker _fizzChecker;
bool isFizz;
[TestInitialize]
...
1
vote
3answers
86 views
How to (really) unit test an adapter?
My question is really simple: shall an adapter (design pattern) class be unit tested, and how?
Example:
I want to create a class ClientSocket with PHP, which is an adapter of the fsockopen, fread, ...
5
votes
2answers
92 views
Is the public interface easy to use and the documentation understandable? Are the unit tests well-written?
I have a year or so of experience in developing in Java. I submitted the solution for this task, but never got the feedback that was promised. Since I still would like to get a feedback on my ...
4
votes
3answers
98 views
Extracting pattern and simplifying testing
I observe the same pattern in a number of my classes but can't extract/abstract it due the tight coupling inside each particular implementation.
Having the class accepting an optional number of ...
4
votes
2answers
67 views
Review of java interface for constructing brain model
I have built a partial human brain model and the following is an example of how I use all the classes. I was wondering if anyone could critique my implementation strategies because I feel like the ...
5
votes
1answer
121 views
Testable code with ORM factory
I'm trying to improve the following code for testability.
public function can_apply_extension()
{
$search_dates = [
...
2
votes
1answer
91 views
What is a better way of organizing a Python project? [closed]
I have some questions to ask on how to better organize a Python project:
Where to put your unit tests scripts?
Where to put your init script?
How to show your module version?
Here is my project ...
1
vote
1answer
105 views
Is this good practice with unit-testing?
I've created unit test for the "student" CRUD operations that looks like this:
[Test]
public void Can_Exec_CrudOps()
{
#region Prepare
var account = Processor.Execute(new ...
2
votes
0answers
177 views
Modelview programming in PyQt4
In my first attempt, I have tried to load images from disk and load it to a QTableView using QAbstractTableModel. I'd like a general code review of this code.
import sys
import os
from PyQt4 import ...
1
vote
1answer
75 views
Feedback on logic implementation and testing
This is my forked branch attempting to make the code better, This is an application for having a slide show of photographs in current directory or supplied as argument.
Use keyboard controls[left to ...
2
votes
0answers
72 views
Symfony2: Extract method from controller, form events, remove conditional
I have a fairly ugly controller method I would like to refactor / extract. I can only test this in a integration type test which kind of signals a code smell.
The method processes the form and needs ...
1
vote
1answer
74 views
Remove duplication in python code for dict schema validation
I want you to look the following code for validating dictionary schemas. There are some libraries out there that do the same thing, but I just wanted to write my own for fun and not to overload my ...
4
votes
1answer
115 views
First ever unit test. Am I headed in the right direction?
I'm learning backbone.js in parallel with unit testing. I've just made a simple model and wanted to unit test it. Do I have the right idea? I am simply making a model with some default values.
...
3
votes
2answers
181 views
Test if two IDictionary objects contain the same values
I'm adding a function to my test library to assist in testing if two IDictionary objects contain the same keys/values.
I need the method to be generic and support a dictionary that has collections as ...
1
vote
2answers
95 views
Improve testability of constructor
I have the following constructor
/**
* @param codePath path to player's code. If ends in '/' it assumes the code is in .class'es in
* a directory; otherwise assumes a jar
* @throws ...
1
vote
3answers
978 views
Make WCF Service testable
I have WCF Service.
Its work fine and I want to have test coverage for it. Unit tests and acceptance.
The problem is static class using in the code.
How is it possible to avoid it?
If it will ...
1
vote
1answer
34 views
Proper way of a testable method with multiple return points [closed]
I have the following piece of java method code:
@Override
public void applyStates(int timestamp, State[] states) {
// Calculate the time diff between current time and the time stamp of the given ...
1
vote
2answers
69 views
Checking name E-mail and unit-test
Please tell me what you think. Is my code bad?
Function checking
#-*- coding: utf-8 -*-
import re
import unittest
def email_check(mail): # E-mail as argument func
compil = re.compile(r"""
...
2
votes
1answer
145 views
Method names for encapsulated unit testing logic. Which convention is better?
I have some C# unit tests which each basically perform the same steps but supply different arguments to the unit under test.
I wanted to encapsulate the logic inside some "helper methods" but found ...
2
votes
2answers
109 views
Testing an Executor
I have written the following Executor:
/**
* <p>This executor guarantees that there is never more than one element waiting to be executed. If an element is
* submitted for execution and ...
1
vote
3answers
55 views
Is my code unit testable
I've written a piece of code. Would like to know is the below piece of code unit testable or does it need any kind of refactoring.
MatchCilentUrls is the primary method for matching two urls. Based ...
1
vote
1answer
41 views
Throwing error if settings / arguments are undefined is this a good breakout function?
var _ = require("underscore");
var checkSettingsUndefined = function(settings){
if(_.isEmpty(settings)){
throw new Error("settings are empty");
}
}
var Class = function(settings){
...
1
vote
1answer
190 views
Code review on an API wrapper in C# wanted
I'm looking for remarks on pretty much anything. This has been my first project that's meant for use by others and I'd like to have it as clean as possible. I will post the main source code here but ...
0
votes
0answers
59 views
Zend Framework and Doctrine 2 - are my unit tests sufficient?
I'm quite new to Zend and unit testing in general. I have come up with a small application that uses Zend Framework 2 and Doctrine. It has only one model and controller and I want to run some unit ...
1
vote
1answer
1k views
Advice on Zend Framework 2 and Doctrine
I've just started looking at Zend Framework 2 and Doctrine ORM, with a view to possibly using it in one of my future products. So far I have a very simple application which allows the user to select ...
4
votes
1answer
327 views
Unit test an ExecutorService in a deamon
To execute tasks sequentially with a timeout I use ExecutorService.submit() and Future.get(). As I don't want to block calling clients, I implement producer–consumer pattern with a queue into a Thread ...
1
vote
1answer
62 views
Can these collision unit tests be improved?
I'm finding it a bit tedious to write unit tests for my collision class because there are so many variations of collisions that need testing. I see repetition in the set-up and assertion stages of ...