unit-testing

How do you write a functional / controller test to check for content added via an AJAX call?

Test def test_generateCashFlowStmt get :getDateRangeForCashFlowStmt xhr :post, :generate_cash_flow_stmt, {:fromDate => {:year=>"2009", :month => "3", :day=>"1"}, :toDate => {:year=>"2009", :month => "3", :day=>"31"} } table = [ .... ] assert_equal table, formatCashFlowStatementAsTable( assigns(...

How to overcome unit test frustration?

I'm a developer and have very much fun at nearly all stages of software developent, from gathering requirements, deciding on language, libraries and tools, sketching the architecture to implementing. Even bugfixing is fun. Unit testing is not. Writing a unit test is not that bad, I can get over it. But the quantity of work involved in t...

C# Noob - Triggering event in mocked interface class - How does this code work?

I'm a little confused at what's going on here. I'm looking at the Puzzle example from Atomic Object showing how to test a Model-View-Presenter pattern Puzzle.zip The View has a private event. The view also has a Subscribe(delegate) function that adds the delegate to the event. The Presenter is passed in an IView and an IModel. Duri...

Is it possible to unit test some AddModelError results in ASP.NET MVC?

Hi folks, i've got a controller method which returns a RedirectToActionResult (sucess!) or a ViewResult (failed with error messages). If the business logic fails, i add the error messages to the AddModelError property. Is there any way i can test this in my MS Unit tests? I also have moq, if that helps too. (i don't believe moq is r...

Automated tests: mocking vs creating test object graph ( using IoC container), what is better under what conditions?

How do you decide what to choose: use mock objects for a test OR create a test object/ object graph using an IoC framework and run test on that data ...

CXX Test Framework for C++

How effective is the CXX test framework, given that you are writing unit test cases around the code that you have written. Any bug in the code might as well get translated into a bug in the unit test code as well? Isn't it something like two negatives make a positive? Also, the time and effort spent on CXX is at least equal to if not m...

Installing nUnit with ASP.Net MVC 1.0

Does anyone have any advice/information on how to install nUnit with ASP.Net MVC? I have seen previous posts which related to the preview releases and involved a ghoulish nightmare of having to create template files, run command prompt and even mess with the registry. Obviously this is far from ideal and given Microsoft's intention to ...

HTTP conformance test suite

Are there any good HTTP conformance test suites? I need to test some existing code for the standard compliance and do not want to reinvent the wheel and bump into various corner cases. I'm not specifying the language I use. I expect suite to be generic enough to be adaptable for my needs – although I'd settle for anything that is sane...

URL parsing test suite

I need to test some existing http:// URL parsing code for compliance to RFC 3986. I do not want to reinvent the wheel and to bump in to various corner cases. Is there some existing comprehensive test suite for that? I do not specify the language I use since I expect the test suite to be generic enough to be adaptable. I would settle ...

How do you mock UnitOfWork from Rhino.Commons?

My application is using Rhino.Commons - NHRepository and UnitOfWork. I like the With.Transaction() syntax for transactions and have been using it for some time. But I ran into a problem - how do I mock a UnitOfWork for testing? Especially this is causing trouble for me: With.Transaction(() => Repositories.TwinfieldSpooler.Update(spool...

Migrating from NUnit to Team System error in Enterprise library configuration

I get this error from my migration of NUnit to Team System when running some of the tests in Visual Studio: Test method XXX.XXX.Data.Tests.Path.Method> threw exception:  System.Configuration.ConfigurationException: Invalid section name. The section 'dataConfiguration' does not exist in the requested configuration file 'C:...

In unit testing how to pass input for hash table

public DataSet ExampleMethod(int param1, string param2, Hashtable ht) { if(ht==null) { ht = new Hashtable(); } ht.Add("testKey","testData"); DataSet ds = new DataSet(); ds.Tables.Add(); ds.Tables[0].Columns.Add("Column1"); ds.Tables[0].Columns.Add("Column2"); ds.Tables[0].Columns.Add("...

Unit Testing: TypeMocking a singleton

Hi I'm using TypeMock Isolater to mock up some objects for some unit tests - attempting to use the AAA api (so the Isolate calls). I have a straightforward singleton class where you call a static GetInstance(), which then returns an instance of the class. I thought it would be a simple matter of mocking that up, but I'm running into a ...

How do i unit test this business logic?

Hi folks, i have a method that does takes in a object and saves it to the database. But, before i save the object, i do the following... (psuedo code) if (IsAuthenticated) { foo.UserId = AuthenticatedUser.Id; } else { foo.AnonEmail = "Jon@World-Domination"; foo.AnonName = "Jon Skeet"; } try { _fooService.Save(foo); } catc...

Unit testing a LINQ2SQL repository

Dear gurus, I am taking my first steps with MsTest and Moq and would like to unit test a Linq2SQL repository class. The problem is that I do not want the unit tests to permantly modify my development database. Which would be the best approach for this scenario? Let each test operate on my real development database, but make sure eac...

Are those unit tests fine?

Hi! I'm trying to grasp test driven development, and I'm wondering if those unit tests is fine. I have a interface which looks like this: public interface IEntryRepository { IEnumerable<Entry> FetchAll(); Entry Fetch(int id); void Add(Entry entry); void Delete(Entry entry); } And then this class which implements that ...

Refactoring a method having dependencies within the same object into something more testable (PHP)

I currently have a method within my class that has to call other methods, some in the same object and others from other objects. class MyClass { public function myMethod() { $var1 = $this->otherMethod1(); $var2 = $this->otherMethod2(); $var3 = $this->otherMethod3(); $otherObject = new OtherClas...

How to use TDD when the fix involves changing the method under test's signature?

I'm trying to get my head around TDD methodology and have run into - what I think is - a chicken-and-egg problem: what to do if a bug fix involves the changing of a method's signature. Consider the following method signature: string RemoveTokenFromString (string delimited, string token) As the name suggests, this method removes all ...

Rhino Mocks AssertWasCalled (multiple times) on property getter using AAA.

I have a mocked object that is passed as a constructor argument to another object. How can I test that a mocked object's property has been called? This is code I am using currently: INewContactAttributes newContact = MockRepository.GenerateMock<INewContactAttributes>(); newContact.Stub(x => x.Forenames).Return("One Two Three"); someobj...

Silverlight Unit Testing - How to check UI base types?

In short: How would I check the type of a UI user control during a Silverlight unit test? In detail: I am loading child views into a ContentControl on a parent view. During testing I want to check that the correct view has been loaded at the correct time. My views are in separate projects, and I don't want to add a reference to those as...