unit-testing

Get/save parameters to an expected JMock method call?

Hi, I want to test an "Adapter" object that when it receives an xml message, it digest it to a Message object, puts message ID + CorrelationID both with timestamps and forwards it to a Client object.=20 A message can be correlated to a previous one (e.g. m2.correlationID =3D m1.ID). I mock the Client, and check that Adapter successfull...

What is 'the' definitive book on Unit Testing?

I would consider myself fairly well versed in the concepts of Unit Testing. I am curious though if there is a publication that is considered the definitive book on Unit Testing. This would be along the same lines as Martin Fowler's Refactoring: Improving the Design of Existing Code being considered (arguably) the definitive book on Ref...

ASP.NET Unit test woes (odd exception error)

I have created a new solution with a minimal amount of code that represents the issue I am having. This is the simplest I could get it down to. namespace EntServ.BusinessObjects { /// <summary> /// Summary description for EntServSession /// </summary> public class EntServSession { public EntServSession() ...

Best tool/framework for testing a RESTful service

I'm looking for a framework or tool for testing RESTful services. This seems like it shouldn't be hard, but the tools that I've found thus far assume things about my service that they probably shouldn't. What would be great is something that could make a request (like, HTTP POST) and then compare the result with an expected result. I ...

How do you make a unit test when the results vary?

I am building an application that queries a web service. The data in the database varies and changes over time. How do I build a unit test for this type of application? The web service sends back xml or a no search results html page. I cannot really change the web service. My application basically queries the web service using HTTPU...

Testing strategy for large application with few public methods?

Hi, I'm working on a project which I'm really not sure how to unit test. It's an unobtrusive tag based framework for wiring up events between models, views and delegates in a GUI system. Basically you have one large json file which is used describes all of the events, event handlers and bindings. The user creates their models, views an...

How to mock ObjectContext or ObjectQuery<T> in Entity Framework?

How to mock ObjectContext or ObjectQuery in Entity Framework? ...

Can automated unit testing replace static type checking?

I've started to look into the whole unit testing/test-driven development idea, and the more I think about it, the more it seems to fill a similar role to static type checking. Both techniques provide a compile-time, rapid-response check for certain kinds of errors in your program. However, correct me if I'm wrong, but it seems that a uni...

Blocks of similar text for test data

For testing purposes I need to create sets of text files that have similar but not identical text. Each set needs to be different from the other set but also share some commonality. For example, I may need to create 10 sets of 20 documents each for a total of 200 documents. Each document needs about 250 words in it. If one of the sets ...

Unit tests to test the Web methods of a Web service which does some database transactions using NUnit

How do I write unit tests to test the Web methods of a Web service using NUnit? The web methods in this application will add,update and delete a record in the database. The unit test will test a web method whether a record has been inserted in the database, the webmethod calls a method in data access layer to perform this action. ...

Do you code review unit tests?

After reading this question I'm left wondering if shops doing code reviews bother to do the unit tests as well? At my current contract all code must be reviewed before commit, but historically unit tests have not been taken seriously. This is an area I'm addressing at the moment and was wondering if people would include the unit tests...

How do you persuade others to write unit tests?

I've been test-infected for a long time now, but it would seem the majority of developers I work with either have never tried it or dismiss it for one reason or another, with arguments typically being that it adds overhead to development or they don't need to bother. What bothers me most about this is that when I come along to make chan...

Setting up Mobile JUnit tests to run under JUnit

I'm using Mobile JUnit, released by Sony Ericsson for unit testing for my J2ME project. I read in the documentation that one can run the tests under regular junit with the help of a few wrapper classes. The documentation, in fact, recommends that you do this if you want to generate reports for CI builds, etc. which is exactly what I want...

How to avoid duplicate code when using mocks in unittests

I am using dependency injection to supply mocks for code outside of my class under test. I find myself writing alot of the same code over and over as I need to mock out AuthProvider, ConfigurationManager, etc. which are used in the method I want to test. The method contains branches (if-then-else) and therefore I have multiple tests in p...

In TDD, what is the advantage of running the tests before even writing an empty method?

I see lots of TDD practitioners following this cycle: 1) Write your test as if the target objects and API already exists. 2) Compile the solution and see it break. 3) Write just enough code to get it to compile. 4) Run the test and see if fail. 5) Write just enough code to get it to pass. 6) Run ...

Unit testing with ASP.NET MVC model binders

I was wondering the best practice for unit-testing controller actions that utilize model binding. [AcceptVerbs(HttpVerbs.Get)] public ActionResult AddProduct(Product product) { } I was wondering how you invoke the controller's method for unit testing. If you try something like this... public void Catalog_AddProduct() { CatalogCo...

Unit testing aspx views

Is there a proper way yet to unit test views with the aspx view engine? I've been playing with various ways that will let me get a parseable string as a result like : view.RenderView(viewContext); But I'm not having any luck so far. Most of what I've read strays into integration test territory. Integration test overlap a fair bit bu...

Testing that an event has an EventHandler assigned

Hi, I'm wanting to test that a class has an EventHandler assigned to an event. Basically I'm using my IoC Container to hook up EventHandlers for me, and I'm wanting to check they get assigned properly. So really, I'm testing my IoC config. [Test] public void create_person_event_handler_is_hooked_up_by_windsor() { IChangePersonSer...

How Do You Create Test Objects For Third Party Legacy Code

I have a code base where many of the classes I implement derive from classes that are provided by other divisions of my company. Working with these other devisions often have the working relationship as though they are third party middle ware vendors. I'm trying to write test code without modifying these base classes. However, there are...

Is Model View Presenter the right choice to make an asp.net UI testable?

I have read many articles on the MVP pattern. Some folks say it is too complex and some say it's outdated. However to me it would seem like the perfect way to provide unit testing access to the UI - which is what I'm aiming to achieve. Have you used MVP and if so what do you think? ...