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
20 views
Node.js: Is this factory method a good approach?
We are beginning to learn Node.js and we are not always sure if we do it the right way. We have a strong object oriented background so the adoption is not always easy. Right now we implemented a ...
1
vote
2answers
39 views
Unit Test to verify number of times lazy initialization logic is executed for a data member
I'll write a small simulation of my actual class first to request insights on unit testing one of the behaviors of this class. Here is my class A:
public class A {
private final String a;
...
2
votes
1answer
100 views
Is a unit test which uses LINQ to check multiple values acceptable?
I'm writing unit tests for a library which parses colors from user input (example: the user input “#f00” gives a red color; the user input “60,100%,100%” gives a yellow color, etc.)
One of the ...
2
votes
2answers
48 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
28 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
53 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 ...
3
votes
2answers
126 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--) {
...
2
votes
0answers
26 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 ...
1
vote
2answers
179 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 ...
1
vote
1answer
51 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]
...
4
votes
1answer
155 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 ...
0
votes
3answers
107 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
154 views
Do I unit test the correct thing
Thats my method to test:
public LessonplannerRequest GetWeeklyLessonplanner(int schoolyearId)
{
Schoolyear schoolyear = ...
4
votes
2answers
74 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 ...
2
votes
1answer
76 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
173 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 ...
1
vote
1answer
89 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:
...
...
4
votes
1answer
118 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 ...
5
votes
3answers
213 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: ...
0
votes
0answers
142 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 ...
3
votes
3answers
102 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 ...
0
votes
1answer
66 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
/// ...
0
votes
0answers
67 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
63 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
98 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
1answer
142 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
0answers
264 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
44 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
40 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
144 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 ...
3
votes
1answer
122 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
211 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
413 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 ...
11
votes
3answers
788 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
3answers
152 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 = ...
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
39 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
167 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
115 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
163 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
626 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
66 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
108 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
110 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
467 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
129 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
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 ...
1
vote
2answers
185 views
PHP class library
I am a PHP newbie, gone through a couple starter tutorials which went ok, so I thought I'd try creating a more complex project to get some experience. It is a NetBeans PHP project where I try to ...