unit-testing

Using factory_girl in Rails with associations that have unique constraints. Getting duplicate errors.

I'm working with a Rails 2.2 project working to update it. I'm replacing existing fixtures with factories (using factory_girl) and have had some issues. The problem is with models that represent tables with lookup data. When I create a Cart with two products that have the same product type, each created product is re-creating the same pr...

Django JSON fixture generation

I'm new to Django coming from Rails, and I am finding the Django fixtures (most commonly JSON from what I gather), to be somewhat awkward and unweildy, at least in comparison to the rails fixtures that I am familiar with. I liked being able to embed some ruby code, e.g <%= Time.now %>, or reference other fixtures by name when relating ...

Simulating race conditions in RSpec unit tests

We have an asynchronous task that performs a potentially long-running calculation for an object. The result is then cached on the object. To prevent multiple tasks from repeating the same work, we added locking with an atomic SQL update: UPDATE objects SET locked = 1 WHERE id = 1234 AND locked = 0 The locking is only for the asynchr...

Java Unit Test: Replace a private method under test

Is there any way of replacing the logic within a private method when running a JUnit test? A bit of background: we have some private methods which interact with bundles within an OSGi container. This is not available in the unit test therefore the methods will fail. We have looked at JMockIt but the method replace functionality seems t...

RhinoMocks AssertWasCalled on mocked object's method that needs to have an object returned?

Using RhinoMocks, I have a catch-22 situation: I want to verify that a method is called, but this method needs to have an object returned on it because the returned object is acted on in the next line. In other words, mocking on the interface just returns a null value, but not mocking it up doesn't give me any way to verify that the meth...

Increase speed for MySQL table creation in Django?

Some of my unit tests take 10-15 seconds just for mysql to create the tables. This seems unnecessarily long. It has to create around 50 tables, but that's still only 3 tables per second. This is a big annoyance when running unit tests over-and-over. As a workaround, I have been running my unit tests in sqlite3. It is blazing fast, but ...

Choosing a test platform for .NET - MbUnit or the one by Microsoft?

I have chosen these two as primary candidates. My thinking goes like this: MbUnit has had a nice start and enjoys a smart, dedicated team of developers. MSFT has many resources and can compete with MbUnit easily if they choose to do so. Which one do you believe I should bet on? ...

Unit testing and encapsulation

I'm trying to get into unit testing, but there's one thing bothering me. I have a php class which I want to unit test. It takes some parameters, and then spits out HTML. The problem is that the main functionality is calculating some values and conditions, and these I want to test. But I have put this in a private method, because normall...

using nUnitASP in webforms

I am new in Unit Testing. I have been asked that nUnitASP can be used to test WebForms. and it is already integrated in VS2008. I am not able to find any way in VS2008 for unit Testing ASP Webforms specifically. Though I know the native method VS provide for UnitTesting, I am quite aware of NUnit using as seperate GUI. I am seeking for a...

Visual Studio Debugger skips over breakpoints

My Visual Studio 2008 IDE is behaving in a very bizarre fashion while debugging a unit test: I have a breakpoint and when I hit it and then try to step with F10 the test concludes. If I Set breakpoints on every line inside the method being tested I will end up at a random one, not the next one on the following line. I have cleaned and re...

Multiple test assemblies in Visual Studio solution file

I have a single visual studio solution containning all the projects (lets say there are five projects). Additionally, the solution also contains test projects for each of the source projects. In all, there are 10 projects under a single solution. When I launch the test view in visual studio it lists tests only from one of the test assemb...

How to trigger script.onerror in Internet Explorer?

The onerror page on MSDN states that the onerror handler can be attached to a script element and that it "Fires when an error occurs during object loading.". For the purpose of unit tests, I am trying to get this onerror handler to fire, but could not find a suitable example. The following code triggers an error in Firefox, but no aler...

qUnit Teardown method

Is it possible to have teardown methods that run after every test in qUnit? If not, are there any plugins around that will do this? ...

Why does VSTestHost.exe load assembly from c:\windows\assembly\temp directory?

I am developing an assembly which has to be installed in the GAC, and as part of a post-build step I ensure that the GAC gets updated after each build. If I create a (Visual Studio) unit test (in a seperate tests assembly) to call a new method on a class under test, then implement the method on the class under test (TDD style), then run ...

How do I test my socket exception handling code?

I have the following code: try { mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, serverPort); mainSocket.Bind(ipEndPoint); mainSocket.Listen(MAX_CONNECTIONS); mainSocket.BeginAccept(new AsyncCallback(serverEndAccept), mainSocke...

Why does ConfigurationManager.OpenMappedExeConfiguration have an extra connection string not in the file?

I'm unit testing my config file for a win forms application. In the LocalTestRun.testrunconfig I set it to copy the app.config. I've checked the Environment.CurrentDirectory while the test was running and the file doesn't have this extra connection string either. This is the test method: [TestMethod] public void Configuration_Connec...

How to model concurrency in unit tests?

I'm pretty new to unit testing and currently experimenting a bit with Visual Studio's testing tools. My question is how to define assertions about concurrent behaviour in these tests. E.g. given a class BoundedChan<T> implementing a bounded channel, how can I specify tests like "channel.Send will not block" or "If the channel's capac...

Is there an alternative to mock objects in unit testing?

It's a Java (using JUnit) enterprise Web application with no mock objects pre-built, and it would require a vast amount of time not estimated to create them. Is there a testing paradigm that would give me "some" test coverage, but not total coverage? ...

How can I ask the SQL server if I have permissions on something? (insert, update,etc)

I'm trying to write a unit test for the database layer that validates the connection string's user has update/insert/read permissions. insert/rollback would create extra gaps in the identity column or launch triggers. for read permissions selecting against the table creates load/work on the sql database and updates when the table was las...

When to introduce unit tests in new projects?

First let me just state that coding without unit testing is just plain crazy. Without unit tests I'm living in constant fear of breaking something without noticing. So I'm all for unit testing, and I prefer doing it using TDD. My question however is; when should you introduce unit tests when starting a new project? Living in the spirit...