unit-testing

Mocking out constructors in Grails

I'm new to testing in Grails, so I'm not sure if I'm taking the correct approach. I am trying to unit test a service (call it FooService) that has an instance of another class (call it Bar) as a property. Basically something like: class FooService { Bar bar void afterPropertiesSet() { bar = new Bar() } } So, I'm trying to test...

Brief "run-down" on setting up Unit Tests in Visual Studio 2008

I am forcing myself to learn test-driven development, and so far I'm enjoying myself. There's a few quirks that Visual Studio Unit Testing has that is driving me batty though. A bit of background information, my project folder looks like this: [Root] BitFlex BitFlex\Code BitFlex\Debug BitFlex\Documents BitFlex\Release Now of course a...

Unit testing Cocoa User Interface

Hi All, Anyone please let me know some links or examples for Unit testing user interface code. Is there a complete example app on that. Thanks in Advance, Bhanu ...

Unit testing in Visual Studio 2008 Standard

I am using Visual Studio 2008 standard editing for my personal projects. This edition does not support unit testing out of the box. I have some experience with the test possibilities in Visual Studio Team System. What (free) options do I have if I want to do unit testing? Is it possible to open the test projects made with Microsoft test...

What unit testing options are available for Silverlight?

Of course there's the Silverlight Unit Test Framework (which seems more like integration testing to me), this port of the NUnit.Framework assembly, and SilverUnit, but what other options are available for Silverlight unit testing? Any good/bad experiences with any one of those (or others)? ...

How to write unit tests for database calls

I'm near the beginning of a new project and (gasp!) for the first time ever I'm trying to include unit tests in a project of mine. I'm having trouble devising some of the unit tests themselves. I have a few methods which have been easy enough to test (pass in two values and check for an expected output). I've got other parts of the co...

The right way to mock (with moq) methods that return mocked objects?

Which of these is correct? var mockLogger = new Mock<EntLibLogger>(); mockLogger.Setup(i => i.CreateTracer(It.IsAny<string>())) .Returns((string operationName) => { var mockTracer = new Mock<EntLibTracer>(operationName); mockTracer.Setup(i => i.IsTracingEnabled()) .Returns(true); ...

How to Unit Test Data Annotation Validators

I'm implementing the Data Validation Validators as shown here: http://www.asp.net/learn/mvc/tutorial-39-cs.aspx This works great at runtime, but how can I Unit Test to verify if I say attribute [StringLength(10)], an error is retured? Regards. ...

Expectation on Mock Object doesn't seem to be met (Moq)

I'm experiencing some odd behavior in Moq - despite the fact that I setup a mock object to act a certain way, and then call the method in the exact same way in the object I'm testing, it reacts as if the method was never called. I have the following controller action that I'm trying to test: public ActionResult Search(string query, boo...

Can this be mocked with Moq?

I am working on mocking some external dependencies and am having trouble with one 3rd party class that takes in it's constructor an instance of another 3rd party class. Hopefully the SO community can give me some direction. I want to create a mock instance of SomeRelatedLibraryClass that takes in it's constructor a mock instance of Som...

Where do you keep your test data files?

Sort of a spinoff of this question. Do you keep them in the source tree? Do you keep them in source control? I'm thinking that if your test cases refer to files, then the files are part of the behavior specification of the system, therefore they're associated with the current version of the system, therefore they should be checked int...

Any tool or way to do a Automated Unit Testing in .NET

Hi , I am developing a ASP.NET application.I have done the unit testing for the application.But i fear that there might be some issues.So is there any way to test the application through some automated process which is a available in .Net. Regards, Jebli. ...

Unit testing of extremely trivial methods (yes or no)

Suppose you have a method: public void Save(Entity data) { this.repositoryIocInstance.EntitySave(data); } Would you write a unit test at all? public void TestSave() { // arrange Mock<EntityRepository> repo = new Mock<EntityRepository>(); repo.Setup(m => m.EntitySave(It.IsAny<Entity>()); // act MyClass c = new...

Unit testing Javascript/JQuery with JSUnit vs Qunit vs XUnit

We are using JQuery and some bit of Javascript in our project. We are thinking of writing some unit test around it for which there are different ways like JSUnit, Qunit, XUnit Can anyone suggest which is the best way to unit test javascript/jquery and if possible with some good link? ...

test the return value of a method that triggers an error with PHPUnit

This question is specific to using PHPUnit. PHPUnit automatically converts php errors to exceptions. Is there a way to test the return value of a method that happens to trigger a php error (either built-in errors or user generated errors via *trigger_error*)? Example of code to test: function load_file ($file) { if (! file_exists(...

Test if a class has an attribute?

I'm trying to do a little Test-First development, and I'm trying to verify that my classes are marked with an attribute: [SubControllerActionToViewDataAttribute] public class ScheduleController : Controller How do I unit test that the class has that attribute assigned to it? ...

Setting the correct InvokeArg when executing Zend Framework controller in Zend_Test harness

According to this mailing list discussion, the recommended way to access the application resources in a Zend MVC controller is: $this->getInvokeArg('bootstrap')->getResource('foo'); This works in production (when browsing to the corresponding Web page). However, when testing a controller action containing this code with Zend_Test_PHPU...

How to run concurrency unit test?

Hi, How to use junit to run concurrency test? Let's say I have a class public class MessageBoard { public synchronized void postMessage(String message) { .... } public void updateMessage(Long id, String message) { .... } } I wan to test multiple access to this postMessage concurrently. Any advice ...

SQLite unit testing NHibernate generated cascade relationships

The following is some background info on this post. You can just skip to the question if you like: In this excellent article (http://ayende.com/Blog/archive/2009/04/28/nhibernate-unit-testing.aspx) the author contends that "When using NHibernate we generally want to test only three things: 1) that properties are persisted, 2) that casca...

At what level should I unit test?

Let's say in my user model I have a ChangePassword method. Given an already initialised user model, it takes the new password as a parameter and does the database work to make the magic happen. The front end to this is a web form, where the user enters their current password and their desired new password. The controller then checks to s...