unit-testing

How to test callbacks with NUnit

Is there any special support when you come to test callbacks with NUnit? Or some kind of of "best practice" which is better than my solution below? I just started writing some tests and methods, so I have still full control - however I think it might be annoying if there are better ways to test callbacks thoroughly, especially if comple...

Help understanding how different kinds of tests are called

I'm making an application similar to Auto Hot Key, which reads some pixels in the screen, makes some computations and then performs some mouse clicks. I have 3 different kinds of tests which I intend to do: I know I'll make use of Unit Tests, for testing indivudal classes to make sure each one of those makes what it's supposed to do. ...

VS 2010 DB Test - Multiple Test Conditions Per Test

I have a UDF that accepts two dates and minute interval, does some date math, then spits out the difference between date1 + interval and date2, honoring business hours. I just found out about VS DB project type and am writing some unit tests. As far as I can tell, I can only set up one context per test, even though multiple Test Condit...

How can I inject an object into another namespace in python?

I'm writing some unittests for code written by someone else here at the office. Python is not my strongest language. While I've been successful with basic unit tests, mocking in python is throwing me for a loop. What I need to do is override a call to ConfigObj and inject my own mock config/fixture into any ConfigObj call. settings.py ...

When doing TDD, why should I do "just enough" to get a test passing?

Looking at posts like this and others, it seems that the correct way to do TDD is to write a test for a feature, get just that feature to pass, and then add another test and refactor as necessary until it passes, then repeat. My question is: why is this approach used? I completely understand the write tests first idea, because it helps ...

Using MYSQL DB, unit testing with HSQLDB = Problems

I recently modified a MYSQL query using the keyword RLIKE however when I ran the unit test which uses HSQLDB in order to mock a database it throws an unknown SQL token exception. In order to resolve this currently I have commented out these tests, but would like to find a work around so I can actually test my code. My google-fu faile...

NHibernate transactions not closing

Out of interest of learning what's going on behind the scenes, I am running some test methods that specifically dump data to my database via NHibernate. I'm toying with various mapping settings and am watching the session processes via the latest version of NHProfiler. I'm noticing something odd, and it may not be of concern, but thoug...

How do I test code that should never be executed?

Following method shall only be called if it has been verified that there are invalid digits (by calling another method). How can I test-cover the throw-line in the following snippet? I know that one way could be to merge together the VerifyThereAreInvalidiDigits and this method. I'm looking for any other ideas. public int FirstInvalidDi...

Is the Create Unit Tests function in Visual Studio worth using on an existing codebase?

In my shop, there isn't much familiarity with unit testing in general, but I'd like to get into it, at the very least, as a proof of concept. Would it be a crazy idea to simply use the Visual Studio function Create Unit Tests on my small (~500 lines) code base and show the concept that way? ...

How to Unit Test algorithms that need to load data from the harddrive (pictures, in this case!) ?

Intro I am doing a kind of OCR application that should recognize characters based on pre-saved .bmp pictures of each character. Now, for a given part of a screenshot of the screen, where I know there will be a character, I want to pass the current picture to a CharacterFactory, that will return a Character object: class CharacterFact...

How to call Application_Start() from TestInitialize method?

Hi, I am working with unit testing for MVC application using visual studio's test project. I need to call Application_start() method from my TestInitialise method of unit test, as my Application_Start initialises some global values which are required for my app. I have also copied necessaty info from web.config to app.config of my test ...

Unit-testing coverage policy, test quality concerns

Hi, our company is trying to increase software quality by enforcing minimum function coverage on automated unit-tests. This is already a good starting point to get at least some tests written and to get them automated (although it would be better to go for branch or decision coverage). My main concern is the outcome of the tests which...

How can I run GWT unit tests when using the google-charts API?

I am using the gwt-google-apis package in GWT so that I can use the visualization API. However, I cannot find a configuration that allows me to run unit tests that use DataTable. Does anyone have a working configuration where a GWT Unit Test uses elements from the visualization portion of the gwt-google-apis? gwt-google-apis: http://cod...

Using Moq to override virtual methods in the same class

We are using Moq to unit test our service classes, but are stuck on how to test situations where a service method calls another service method of the same class. I tried setting the method being called to virtual, but still couldn't figure out what to do then in Moq. For example: public class RenewalService : IRenewalService { //w...

How do I stub out the flickraw library in my app's unit tests?

My Rails 2 app displays a slideshow of photos from Flickr via the flickraw library. My code works, but I'm stuck on how to properly write RSpec unit tests. I have a Slide class that encapsulates everything that my app needs from flickraw. It acts somewhat like a model object but doesn't use ActiveRecord. It doesn't do much work; it de...

Testing Repositories in Entity Framework

Hi I'm new to EF but am trying to go by the book and create tests for my repositories. The tests fails here. desiner.cs base(global::System.Configuration.ConfigurationManager.ConnectionStrings["pij_localConnectionString"].ConnectionString, mappingSource) I presume I need to move the connection strings out of the webconfig. What is t...

Running only part of the set of all tests with MSTest

I'd like to know if there is any simple way of running with MSTests a certain category of tests. I currently have some Unit and Integration tests. Generally, I just want to run Unit-Tests. I know you can tag each test method with a category, but from what I've seen it seems like it is only useful if you want to create different tests li...

How to develop a StopWatch class test first?

I'm currently trying to implement a StopWatch class. The interface is something like: interface IStopWatch { void Run(); void Stop(); int SecondsElapsed { get; } int MinutesElapsed { get; } } Basically my app will need to use a StopWatch, but for testing purposes it'd be nice to have a way of artifially modifing a Stop...

Different behavior/content of Spring/Hibernate/SessionFactory when running Maven+Surefire vs Eclipse+jUnit

I try to be quick. In fact, one of my jUnit test is failing when running the Maven command of my project (mvn install, so with the Surefire plugin) while it's successful when I run it in Eclipse. I tried many things and the only difference I managed to see is that : - With Maven/Surefire in debug-mode, in the Hibernate-SessionFactory I...

Find what class an abstract class is bound to in Ninject

Hi, How do I find what class is currently bound to the abstract class with Ninject in the following example: if(conditional) Bind<IProducts>().To<Products>(); else Bind<IProducts>().To<SqlProducts>(); Type currentType = 'Type based upon current binding of IProducts' How can I get the value of currentType. ...