unit-testing

Testing a background worker with rhino mocks

lets say i have a background worker in a class that perform db query in a background thread. i wanna test this class so i mock my db and return some collection so far so good, make sure my background worker called the do work and than i wanna make sure that the finish also happened. I've noticed that the test pass and fail randomly (...

Unit Testing a large method

Following Test-Driven Development that is. I've recently implemented a algorithm (A*) that required a clean interface. By clean all I want is a couple of properties and a single search method. What I've found hard is testing the search method. It contains around five steps but I'm essentially forced to code this method in one big go ...

Setup Google Test (gtest) with Eclipse on OS X

What is the procedure to setup Google Test to work under Eclipse on Mac OS X? I followed the instruction in README to compile and install gtest as framework from XCode. Now I want to use gtest with Eclipse. Currently, it compiles fine but fails during build. I suppose Eclipse does not use framework concept as XCode does and need a diff...

SimpleTest Mock objects: clearing expectations

The short question: Is there a way to reset a Mock object in SimpleTest, removing all expectations? The longer explanation: I have a class that I'm testing using SimpleTest and am having some problem with the Mock objects it is using. The class is a Logger, and inside the logger are a number of Writer objects (FileWriter, EmailWriter,...

Moq a proxy for unit testing

Dear all, I'm new to using Moq and I cannot find the way for doing this. I've a generateId private method, called /// <summary> /// Generates a call Id for external interfaces /// </summary> /// <returns></returns> private string GenerateCallId() { return "EX" + SharedServicesClientProxy.Instance.GenerateId().ToString(); } I wanted t...

Does NUnit's Is.EqualTo not work reliably for classes derived from generic classes?

Today I ran into the following problem with NUnit. I have a class, that derives from a generic class. I started to do some serialization tests and tested for equality using the Is.EqualTo() function of NUnit. I started to suspect something is wrong, when a test that should have failed passed instead. When I used obj1.Equals(obj2) inste...

BDD Testing frameworks - RSpec and Cucumber

I was looking into RSpec and cucumber and was wondering what this adds to unittesting? On the one hand you may say that having "stories" or more readable tests is a plus, but doesn't all this aliasing of functions names go against using unittests as examples of code usage? ...

Using Moq: mock object throwing 'TargetParameterCountException'

I am new to Moq, so hopefully I am just missing something here. For some reason I am getting a TargetParameterCountException. Can you see what I am doing wrong? Any questions? Please ask. :) Here's my code: [Test] public void HasStudentTest_SaveToRepository_Then_HasStudentReturnsTrue() { var fakeStudents = new List<Stude...

How can I test a Singleton class with DUnit?

Or it's better to use another Design Pattern? ...

How-To Mock MSMQ MessageQueue

Hi, I want to Unit Test my application which use MSMQ but i found no way in order to Mock MessageQueue objects. var queuePath = @".\Private$\MyQueue"; MessageQueue queue = null; if (MessageQueue.Exists(queuePath)) { queue = new MessageQueue(queuePath); } else { ...

Using MBUnit to test values against a database

I need to test a class who's return value depends on values from a database. I could just hit the database in the unit test but those values could change. Is there a standard solution to this? ...

Mock system call in ruby

Know of a way to mock %[]? I'm writing tests for code that makes a few system calls, for example: def log(file) %x[git log #{file}] end and would like to avoid actually executing system calls while testing this method. Ideally I'd like to mock %x[..] and assert that the correct shell command is passed to it. ...

Yet another unit testing / code coverage question. Is my approach sane?

This is yet another Unit Testing question. I'm trying to draw knowledge from a number of places regarding how to proceed, and I wanted to bounce my current understanding off of the collection of experts here. assume a project for which all dependencies except opengl funkiness are statically linked (except the c run time) My current un...

Unit testing a function that does not return anything in Javascript

Hi all: As topic suggested, how can I unit test a function that does not return anything (apart from null checks that simply returns)? And also, how do I unit test the functions within a function which also does not return anything especially if they are at the last lines of a function? The reason behind this question is that I've bee...

Test an application

Hi Can every one tell me about type of test in a application. I heared about TestCase, UnitTest, FunctionalTest and another type of test, but I don't know these discription and usage of these. Please help me to understanding all about Test Process in an application. ...

Is it okay if my unit tests contain 1-2 methods per class?

When I'm testing my simple geometric library, I usually have one or two methods in every test class. All I check is whether objects do proper coordinates calculation or not. Is it okay (meaning the number of methods)? ...

Best practices for writing parallel unit tests

I'm looking into using parallel unit tests for our project(s) and was wondering about any best practices for actually writing such parallel unit tests. ...

How to JMockIt System.getenv(String)?

What I have right now I have a 3rd party singleton instance that my class under test relies on and that singleton is using System.getenv(String) in its constructor. Is it possible to mock this call? I tried this JMockIt Example new Expectations() { System mockedSystem; { System.getenv( "FISSK_CONF...

Django formset unit test

I can't running Unit Test with formset. I try to do a test: class NewClientTestCase(TestCase): def setUp(self): self.c = Client() def test_0_create_individual_with_same_adress(self): post_data = { 'ctype': User.CONTACT_INDIVIDUAL, 'username': 'dupond.f', 'email': '...

Please help me understand Unit Testing.

What exactly is a unit test and how do I write one? I hear many times people write them before their app is even written, how can this be? I am under the impression that a unit test is some code that makes a call to a method of your app with a set value and expects a specific value to come back, if the specific value does not come back t...