unit-testing

Rhino Mocks vs Moq for Silverlight

We are Silverlight Unit Test Framework for testing. Which one will be better for my team? Rhino Mocks or Moq. No one has any experience with using a framework like this. What are the pros and cons of using each framework in this environment? ...

Strict Mocks using AAA syntax of Rhino Mocks

Hi, Is it possible to create a "strict" mock using the new AAA syntax of Rhino Mocks? The issue I am seeing is that the library I am mocking often returns null as a valid return value (which I handle in my function), so using the default mock I can never be sure if I tested all paths or I forgot to set some expectations. ...

Unit testing a function that outputs via XmlWriter?

I'm trying to get into the unit testing and TDD way of doing things but I've come across a problem I'm not sure what to do with. I have a collection that saves itself to disk using XDocument and XmlWriter. I know you shouldn't write the file to disk then check it so I had the XmlWriter output to a memory stream then I checked the conte...

how unittest serialization and db access

What is the correct way to write unittests for things like serialization/deserialization or writing and reading objects to/from a repository? Should I test if each and every property of my objects is correctly read and written? This seems like quite a lot of work when I have lots of types with lots of properties. Is this the way to go? ...

How (strategy) to unit test properties (get/set) in BDD style?

I have a class (of many) that have properties. Some have logic in them and some don't. Assuming I want to test these properties, how do I go about doing that? Recently, I've been interested in BDD style for creating unit tests. see here and here. So I'd do a setup of the context - basically create the SUT and load up whatever is nee...

Java unit tests, directory layout

When building a suite of unit tests for Java code, is there a convention for where to place test code in relation to source code? For example, if I have a directory /java that contains a bunch of .java source files, is it better to put the test cases in /java itself or use something like /java/test. If the latter is preferred, how do y...

How to write good Unit Tests?

Can anyone suggest books or material Unit Tests? Some people consider codes without unit tests as legacy codes. Nowadays, Test Driven Development is the approach for managing big software projects with ease. I like C++ a lot, I learnt it on my own without any formal education. I never looked into Unit Test before, so feel left out. I thi...

Visual Studio - Unit tests loading resources in the project

Consider a VS Test project looking like this: The goal is to run some tests given some data in those Xml files. How would you easily load a given Xml file into an XmlDoc within the unit test methods? Current state is: XmlDocument doc = new XmlDocument(); string xmlFile = "4.xml"; string dir = System.IO.Directory.GetCurrentDir...

Adding unit tests to legacy code

Have you ever added unit tests, after the fact, to legacy code? How complicated was code and how difficult to stub and mock everything? Was the end result worthwhile? ...

Unit testing with UI automation

... for .NET with VS Team System Test Ed? Yes I know I should make my UI thinner, but I'm working with old code and I'd like to unit test the current state before I make major refactorings. I've tried NUnitForms and White, but they seem to have a non-obvious dependence on NUnit. I get thread locking/managed code execution errors whene...

Testing modules in rspec

What are the best practices on testing modules in rspec? I have some modules that get included in few models and for now I simply have duplicate tests for each model (with few differences). Is there a way to DRY it up? ...

Grails unit testing help needed

I want to test a Grails controller which calls a service. I'd like to mock the service. The Service has a method: JobIF JobServiceIF.getJob(int) and JobIF has a method: String JobIF.getTitle() Here's my controller def workActivities = { JobIF job = jobService.getJob(params.id) [career:job] } I understand that I need to mo...

How do you test dependent classes that cannot be unit tested together?

I have a question about how to test 2 classes which have a dependency between each other, but cannot be unit tested together. I am not able to create a short enough code example so I will attempt to explain it with hypothetical classes. Sorry if this is too confusing, but I am still trying to come up with a succinct example. In this e...

LazyInitializationException while unit-testing Hibernate entity classes for use in Spring, using TestNG

Hi guys, In my Spring configuration, I've asked that the session should remain open in my views: <bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"> <property name="sessionFactory" ref="sessionFactory"/> <property name="flushMode" value="0" /> </bean> ...

How to make HttpUnit to send submit button name on form submit?

I have a single form with two submit buttons. Server side discovers proper intention by checking if submit button name is in the request parameters. Unfortunately I failed to test it with HttpUnit - looks like HttpUnit does not include the button name in the request parameters. I simulate the click by: dialog.clickButton(<button-id>) ...

Is there a way to run unit tests sequentially with MSTests?

I am working in an application that is mostly single-thread, single user. There are a few worker threads here and there, and they are only using thread safe objects and classes. The unit tests are actually testing those with multiple threads (explicitly created for the tests), and they test fine. The VSTS unit tests fail when testing bu...

Test::Unit tests passing on OS X, erroring out on CentOS

I have a set of Test::Unit tests for a Rails application. It was developed on OS X under Ruby 1.8.6, Rails 2.3.4. I'm also using thoughtbot-shoulda 2.10.2. I'm using standard Rails fixtures, not factories. I've checked out the project onto a CentOS Linux 5 workstation for another developer to work on. He's running Ruby 1.8.7. (The ap...

Database Mocking on a large system in Silverlight and RIA Services

I am using Silverlight, Ria, and the Silverlight Testing Framework. I am trying to build a mock database and have run into a few issues. First the example on the RIA site does not use the silverlight testing framework so I am not able to use it. Second The other example that I have tried does not seem very scalable. Since I need to mo...

Rails unit testing doesn't load fixtures

Hello together, rake test:units fails in my current application, because the needed data of the fixtures is missing. If I'm loading the fixtures manually via rake db:fixtures:load RAILS_ENV=test the unit tests are working, but rake purges the test database. My test_helper includes fixtures :all and my tests are inheriting from it - bu...

Dependency injection in NerdDinner - actually testing your repository or model

Consider a beginner dealing with Dependency Injection. We're analyzing two relevant classes in NerdDinner. DinnerRepository from the application: FakeDinnerRepository from the tests: They implement different logic, which of course is necessary, as the key idea here is to implement the IDinnerRepository, and provide different impleme...