Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
0
votes
0answers
10 views
Two dimensional unit testing
Consider a process composed of three algorithms: makeRuns, meld and traverse (each taking the output of the previous one as input): it is interesting to test each separately. Now consider three (or ...
2
votes
1answer
26 views
Generic test serie for various solutions to the same algorithmic problem
I am learning how to use the module unittest for test-driven development. Below is a simple yet practical example of an issue I will have many times: one single problem (e.g. an Abstract Data Type ...
2
votes
1answer
44 views
Unit test provider roles
I am unit testing this role provider. I have a few asserts in the code for my test. I am sure there are more test I could preform. Does anyone have any suggestions for more test for this role of the ...
1
vote
1answer
83 views
Production code to be good for unit testing
I would like to advise if the following production code is good to be unit tested. The segment of the production code gets data from a backend service and displays it on the page. It is a class:
...
...
1
vote
1answer
124 views
How to refactor my controller specs?
In my project (https://github.com/GCorbel/comment-my-projects) I have this kind of code to test my controllers.
#encoding=utf-8
require 'spec_helper'
describe ProjectsController do
let!(:project) ...
1
vote
1answer
129 views
Testing the same code with different input data
I would like to get an advice regarding how to test the same code with different input data.
I would like to test that method operationSucceeded will be invoked for all successful status codes. Here ...
1
vote
2answers
96 views
FooTest or FooTests? [closed]
Can't make up my mind. For a class Foo, should its test class be called FooTest or FooTests?
3
votes
2answers
122 views
How can I optimize this code for unit testing
How can i optimize this code with less number of loops and return values for unit testing
public class Diamond {
public void DiamondShape(int num) {
for(int ucount=num;ucount>0;ucount--) {
...
1
vote
2answers
175 views
Am i fake testing or this is how mocking should be implemented?
I'm new to Rhino mock and i would like to know if the test i did is not fake testing as i red a lot about it. are there any improvements need to be done?
[Test]
public void ...
2
votes
0answers
22 views
Shaky on QUnit folder structure
I want to write something serious in JavaScript for the first time in my life. Knowing this, I want to do TDD and write unit tests. I have experience in JUnit, but yet, how to structure my project ...
4
votes
1answer
151 views
How do I make this code unit-testable?
I have a functionality that imports data into a database, based on an Excel workbook and some meta data (both user-supplied). The functionality implements interface IFunctionality which essentially ...
1
vote
1answer
48 views
unit-testing / mocking a class which contains functionality which depends on itself
Take the below code:
public interface ISettingsManager
{
SettingData GetSettingByIdentifierOrCreateIfDoesNotExist(Enum identifier);
T GetSetting<T>(Enum identifier);
}
[IocComponent]
...
0
votes
3answers
90 views
I need help improving this design for easy unit testing - C#
I am very new to unit testing, I only read a few chapters from 'Art of Unit Testing' and know how to write basic unit tests. I have a deadline for a project so I plan to read 'Professional Test Driven ...
1
vote
1answer
146 views
Verify collection as a method parameter
How can I verify that ohterClassMock.MethodToTest() was called with contracts?
That it was called with contract, that have Id = 1 and Param2 = 34 and also with contract2, which has Id = 2 and Param2 ...
4
votes
2answers
65 views
Recursive XML2JSON parser
I made a Python function that takes an XML file as a parameter and returns a JSON.
My goal is to convert some XML get from an old API to convert into Restful API.
This function works, but it is ...
0
votes
1answer
62 views
how should you mock / unit test this method / class
I have the below code:
public interface IRepositoryService
{
/// <summary>
/// This will add conditions like Published = true, Deleted = false and PublisehdDate smaller than NOW
/// ...
3
votes
1answer
131 views
Do these unit tests cover my method under test?
I've written an extension method to truncate strings:
/// <summary>
/// Returns the string, or a substring of the string with a length of <paramref name="maxLength"/> if the string is ...
4
votes
2answers
149 views
Do I unit test the correct thing
Thats my method to test:
public LessonplannerRequest GetWeeklyLessonplanner(int schoolyearId)
{
Schoolyear schoolyear = ...
2
votes
1answer
63 views
Testing database table creation with NUnit
I'm new to using NUnit and have written a test to check for the existence of a database table. I have the below code that should check whether a new table named NewTable has been created in the ...
5
votes
0answers
164 views
Doubts about the quality of an API designed for use with minimal effort
This is going to be long, and I do hope it is going to make some kind of sense; I apologize if it doesn't. I'll try to provide exactly the amount of context that is necessary to understand the ...
3
votes
3answers
100 views
Test Driving Interface Design
I have been doing TDD since I have started my first job out of university (about 5 months ago), most of which is working with legacy code. I started a personal project today and thought I would TDD ...
8
votes
3answers
807 views
Unit testing legacy code with static classes
I am adding new functionality into a legacy application. For my new classes I have introduced Unit Testing. I still need to work with the existing code.
One of the problems I face is that a lot of ...
5
votes
3answers
199 views
Maximum Sub-array Problem
I started taking a look at a programming challenge I had read about earlier today on 8thlight. Unfortunately, it seems to have been taken down and all I could remember about it was the problem posed: ...
4
votes
1answer
105 views
How to make static methods testable?
I am creating an application which will be testable(unit + integration). In this application I have a FileHelper static class,
public static class FileHelper
{
public static void ...
0
votes
0answers
123 views
I implemented a User model with BackboneJS and RequireJS with test cases in Jasmine. How can I improve?
I've been taking a stab at implementing test cases using the Jasmine testing framework. To do so, I've made an application which has a User object. This User object is created by the server, but its ...
0
votes
0answers
61 views
Testing WordPress with Mockery and a Facade
I've put together this gist with an idea about testing WordPress themes and plugins with Mockery and a WordPress facade object. I've love some feedback on the approach, please.
WordPressFacade
...
1
vote
0answers
54 views
Does this nodeunit test conform to best practices?
I have inherited a node-js project, and I am completely new to it. Fortunately, it is already covered by unit tests.
The class under test, FmsRescuers, has the responsibility of sending HTTP requests ...
1
vote
2answers
91 views
Is my code (clean code separation) is correct?
The code below is an approach of clean code separation, but I am confused if it is a right approach or wrong. Please suggest me.
public interface IRepository<T>
{
...
1
vote
0answers
218 views
flask-SQLAlchemy models and unit-testing
I believe this post belongs here vs stackoverflow or Database administrators but let me know if i'm wrong. This is my first time building anything remotely like a robust database. I'm midway through ...
2
votes
1answer
43 views
Testing a mixin function
I have a mixin function which is as follows -
function mixin(receiver, supplier) {
for (var property in supplier) {
if (supplier.hasOwnProperty(property)) {
...
-1
votes
1answer
39 views
Review tests first [closed]
I am going to adopt TDD in our team and one of the ideas I have is to review tests first. So one would write interfaces, mocks, and tests first, submit them for a code review and once interfaces and ...
3
votes
1answer
117 views
Test Driven Development, Mocking & Unit-testing
I have the below code which is still under development - but I'm trying to get myself to find the ideal way to move forward.
public interface IMemberSubscriptionService
{
void ...
2
votes
1answer
194 views
Ranking and sorting on Array/List
My apology, I am quite new to posting a question in this forum.
I had a task where I was supposed to write a solution to sort entries(Name, score - in an array/list) in order of score and generate ...
5
votes
3answers
354 views
String calculator kata
I'm new to C# and just tried the String Calculator Kata for practice. What I like to know is if you (as more experienced C# programmers) have some suggestions for improvement with the end result ...
2
votes
2answers
162 views
How to use inversion of control within a strategy when using the strategy pattern
I am creating a skeleton application to demonstrate use of the Strategy design pattern and inversion of control inside a Strategy.
The application is the backend of a simple board game, which also ...
4
votes
3answers
146 views
Is this UnitTest for updating an object in data-access layer sensible?
I'm still trying to learn how to write good tests (and write testable code).
This is the function I want to verify,
void IAutoTisDal.UpdateRange(Range range)
{
using (var repo = ...
11
votes
3answers
781 views
Which Unit Test is correct? They both test the same thing in different ways
Below both Unit Tests pass and they both test the same thing. Which is the production code uses the right error codes.
The short question is which test is correctly Unit Testing expected behaviour ...
4
votes
4answers
1k views
Function for determining triangle type?
A while back I was asked to write some sample code for a job that I was applying for. They wanted a class that had a function that would accept three lengths and return the appropriate type of ...
1
vote
1answer
38 views
Thoughts on the testability of my use case interactor?
So here is a class that executes the CreateAPerson use case. It takes a request object (which is a simple data structure), validates the request, creates a new person, and then returns a response ...
2
votes
1answer
154 views
Better way to Unit Test this?
Basically I have some methods that access the file system and to avoid that in the unit test I have broken those sections out into a protected virtual method. In the Unit Test I then use Moq to setup ...
3
votes
1answer
112 views
Designing a listener method and making it Testable
I have a java based server application that needs to support multiple clients. In the main class I have a method that runs in an infinite loop and waits for client connection. Following is this ...
3
votes
1answer
160 views
Tips for Making this Code Testable
So I'm writing an abstraction layer that wraps a telephony RESTful service for sending text messages and making phone calls. I should build this in such a way that the low-level provider, in this case ...
3
votes
1answer
519 views
Unit Testing Code that Calls RESTful API
So I'm writing a library which calls a RESTful API and then performs some work on the data. I've architected my code like this:
I have a class, let's call it APIRequestor that initiates a call to the ...
1
vote
1answer
64 views
Creating many random test database entries (updated with stored procedure)
Working on a simple time sheet webapp, I have created the following query (simplified - I actually have several mapped columns of a similar type to project_id) to generate test data:
INSERT INTO ...
3
votes
1answer
2k views
Convert number to words (web application)
I'm looking for a new job, and a company who had a role I was going for asked me to do a programming exercise. It consisted of making a web application of two or more pages that took a person's name ...
1
vote
2answers
106 views
Get resources inside or outside constructor?
I need your opinion on writing a constructor that's clean code and unit test friendly.
Option 1 :
var res1 = bigObject.GetResource1();
var res2 = bigObject.GetResource2();
var res3 = ...
0
votes
0answers
105 views
Testing Backbone Model using Jasmine
It is the first time I write a javascript test for a Backbone Model.
Looking in the web resource there are not so many items about this subject.
I found this one, Testing Backbone applications with ...
2
votes
2answers
448 views
Tesing a simple calculator class with JUnit/JMock
I'm playing around with JMock and trying to understand whether I understand the idea correctly.
There's an interface Printer aimed to print integers somewhere. There's an interface Calculator aimed ...
1
vote
1answer
149 views
Spotify Best Before puzzle
I thought to spent my free time by solving a puzzle: Best Before Spotify Puzzle.
I coded in Java, and yeah I did not clean up my code (just a rough work) and I have yet to optimize... so I did check ...
3
votes
3answers
791 views
How to unit test this method?
I have this method inside a class that is responsible for setting up and executing a model:
public FlowJob PrepareAndScheduleFlowModelJob(string coordinates)
{
GeometryCoordinateString ...

