unit-testing

Unit testing UDP socket handling code

Are there any 'good' ways to cause a thread waiting on a recvfrom() call to become unblocked and return with an error? The motivation for this is to write unit tests for a system which includes a unit that reads UDP datagrams. One of the branches handles errors on the recvfrom call itself. The code isn't required to distinguish between...

Why does this asp.net mvc unit test fail?

I have edited and simplified this question a lot. If I have this method on my HomeController: public ActionResult Strangeness( int id ) { StrangenessClass strangeness = null; if( id == 1 ) { strangeness = new StrangenessClass() { Name="Strangeness", Desc="Really weird behavior" }; } ...

How to test Guice Singleton?

Guice Singletons are weird for me First I thought that IService ser = Guice.createInjector().getInstance(IService.class); System.out.println("ser=" + ser); ser = Guice.createInjector().getInstance(IService.class); System.out.println("ser=" + ser); will work as singleton, but it returns ser=Service2@1975b59 ser=Service2@1f934ad its...

How to build a test group in watir?

I have some single watir.rb scripts that use IE and are written in a standard watir way. How do I create a test group that combines them? I want all of them be executed by executing the main script. Is it possible to auto include single test files into a test group by subidr? Is it possible to enumerate the files that should be includ...

Do we really need isolation frameworks to create stubs?

I have read this: http://martinfowler.com/articles/mocksArentStubs.html My concepts about a stub and a mock are clear. I understand the need of isolation frameworks like moq, rhinomocks and like to create a mock object. As mocks, participate in actual verfication of expectations. But why do we need these frameworks to create stubs. I wou...

Running each JUnit test in a separate JVM in Eclipse?

I have a project with nearly 500 individual tests in around 200 test classes. Some of these tests don't do a great job of tearing down their own state after they're finished, and in Eclipse this results in some tests failing. The tests all pass when running the test suite from the command line via Ant. Can I enable 'test isolation' some...

How to test reliability of my own (small) embedded operating system ?

I've written a small operating system for embedded project running on small to medium target. I added some automated unit test with a high test code coverage (>95%), but the scope is only the static part. I got some code metrics as complexity and readability. I'm testing my code with a rule checker with MiSRA support, and of course fixe...

Implementing a Stack using Test-Driven Development

I am doing my first steps with TDD. The problem is (as probably with everyone starting with TDD), I never know very well what kind of unit tests to do when I start working in my projects. Let's assume I want to write a Stack class with the following methods(I choose it as it's an easy example): Stack<T> - Push(element : T) - Pop() : ...

Open source projects with good quality tests

Hi, I know there is a thread about open source projects with good code quality, but which projects have unit tests (With mocking) and are of a high quality? Many Thanks ...

How to emulate onLowMemory()?

I have put some instructions in onLowMemory() callback and want to test the same. Is there a "direct" way to test onLowMemory function of the application subclass? Or will I have to just overload the phone by starting many apps and doing memory intensive tasks? Thanks. ...

How do I test UrlHelper.RouteUrl()?

I'm having a tough go trying to figure out what I need to mock in my tests to show that UrlHelper.RouteUrl() is returning the right URL. It works, but I'd like to have the right test coverage. The meat of the controller method looks like this: var urlHelper = new UrlHelper(ControllerContext.RequestContext); return Json(new BasicJsonMess...

How do I unit test a finalizer?

I have the following class which is a decorator for an IDisposable object (I have omitted the stuff it adds) which itself implements IDisposable using a common pattern: public class DisposableDecorator : IDisposable { private readonly IDisposable _innerDisposable; public DisposableDecorator(IDisposable innerDisposable) { ...

How can I unit test django messages?

In my django application, I'm trying to write a unit test that performs an action and then checks the messages in the response. As far as I can tell, there is no nice way of doing this. I'm using the CookieStorage storage method, and I'd like to do something similar to the following: response = self.client.post('/do-something/',...

How to simulate a file read error in the CRT

Using VS2008, we would like to simulate a file that has a size of X, but that has a read failure at X-Y bytes, so that we get an error indication. Anyone have an idea of how to do this on windows? Looks like there is a solution for linux, but I can't really come up with a way to do this on windows. We have multiple developers, multiple...

Assert.AreEqual() Exception in VS2010

I am fairly new to unit testing and am using VS2010 to develop in and run my tests. I have a simple test, illustrated below, that simply compares 2 System.Data.DataTableReader objects. I know that they are equal as they are both created using the same object types, the same input file and I have verified that the objects "look" the sam...

How can I change ruby log level in unit tests based on context

I'm new to ruby so forgive me if this is simple or I get some terminology wrong. I've got a bunch of unit tests (actually they're integration tests for another project, but they use ruby test/unit) and they all include from a module that sets up an instance variable for the log object. When I run the individual tests I'd like log.level...

Include Unit tests in the same package as the source code in Java

I'm getting back into Java after a long stint in the Ruby world and I've got a question about JUnit tests and the source I'm testing. If I've got a package of graphics code for my company, lets call it com.example.graphics, should I include my tests in that package too or should they be included in a seperate package, like com.example.g...

is there a less bloated way to test constraints in grails?

Is there a less bloated way to test constraints? It seems to me that this is too much code to test constraints. class BlogPostTests extends GrailsUnitTestCase { protected void setUp() { super.setUp() mockDomain BlogPost } void testConstraints() { BlogPost blogPost = new BlogPost(title: "", text: "")...

Can I write a test without any assert in it ?

Hi, I'd like to know if it is "ok" to write a test without any "assert" in it. So the test would fail only when an exception / error has occured. Eg: like a test which has a simple select query, to ensure that the database configuration is right. So when I change some db-configuration, I re-run this test and check if the configuration ...

Ms Test or NUnit?

Is there any advantage to picking NUnit for unit/integration testing vs the built in MsTest? ...