Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.
1
vote
1answer
60 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 ...
3
votes
1answer
46 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
39 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 ...
0
votes
2answers
55 views
Using MOQ In Unit Testing
I am fairly new to writing unit tests, and I was wondering if this approach I have taken is on the right track?
Given the following interfaces/classes:
public interface ILoggingService
{
void ...
0
votes
0answers
24 views
Guice custom behavior for testing, how is this solution?
I have a Java/Swing/Guice application that uses multiple frames. When the application runs normally, I just want some of these frames to hide (and the "master" frame can unhide them).
When testing ...
1
vote
0answers
61 views
Unit testing event triggering
I am writing a unit test for a Dispatcher that will route a HTTP request to a specific Controller and invoke a specific method on that Controller. It will also trigger various events at different ...
1
vote
2answers
90 views
Refactor code to make it more testable
I have this code that works fine. But I would like to create some unit test for this class. Most of the code is in private or void type methods. Please help me refactor my class to make it more ...
3
votes
1answer
55 views
32-bit counter and test bench
How could this VHDL counter and its test bench be improved? I am interested in anything you see that could be done better, but especially in the test bench:
Is wait for 10 ns better or worse than ...
1
vote
0answers
90 views
My first tests: test mongoose model (node)
I have mongoose model:
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
Imager = require('imager'),
env = process.env.NODE_ENV || 'development',
config = ...
0
votes
2answers
103 views
Is my JavaScript test actually testing anything worthwhile here
Given a production module like this:
function ($) {
var
showForm = function () {
$.get(url, function (html) {
$('body').append(html);
});
};
...
6
votes
1answer
274 views
Is this the proper way of doing timing analysis of many test cases in Python or not
Chat room for discussing this question.
I am learning about timing analysis in Python. I used time module before it was pointed out that timeit module would be better for timing analysis.
My main ...
0
votes
0answers
65 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
48 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
135 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
57 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
31 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
76 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
135 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
37 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
184 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
63 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]
...
5
votes
1answer
196 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
141 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
153 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
159 views
Do I unit test the correct thing
Thats my method to test:
public LessonplannerRequest GetWeeklyLessonplanner(int schoolyearId)
{
Schoolyear schoolyear = ...
4
votes
2answers
105 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
144 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
191 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
110 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
164 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
269 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
168 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
107 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
85 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
91 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
89 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
115 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>
{
...
2
votes
1answer
174 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 ...
2
votes
0answers
396 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
50 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)) {
...
3
votes
1answer
164 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
129 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
274 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
630 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
807 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
193 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
2k 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
42 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
234 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
119 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 ...