unit-testing

Using Rhino Mocks how can I set a property of a parameter for a Mocked method

Using the new Rhino Mocks 3.5 Arrange/Act/Assert (AAA) Testing style, I'm having problems writing a test. I have a method that calls a method on a repository class. ActivateFoo, where my Foo object has an IsActive property. The result of the ActivateFoo object should change the property. Here is sample code: [TestMethod] public void ...

Check for garbage collection in .NET?

Is there a way of checking if an object was collected by the Garbage Collector in .NET? I'm trying to write an API that'll hook onto some events of objects that are passed in, and I need to make sure I don't use strong references to the object. I know how to do this, but I'd also like to write a unit test to verify this, and that I don'...

Unit testing Tool for Sybase database

Do we have any tools to unit testing Sybase databases around? i am not able to find one in http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks i am looking out for a tool that can allow me to unit test Stored procedure.Something like wee do with utPLSQL.This tool will be used by Database guys to unit test. ...

Visual Studio Unit Test - The member specified could not be found.

Getting an odd problem with a unit test in my solution. One of the test always fails with the following error message: The member specified (BuildMap) could not be found. You might need to regenerate your private accessor, or the member may be private and defined on a base class. If the latter is true, you need to pass the ty...

Unit test constructor that uses My.Settings

I have a constructor that looks like this: Public Sub New() MyBase.New() ws.Url = My.Settings.WebServiceURL End Sub (ws is private) Is there any point in unit testing this? The class did not previously have this constructor. ...

Mocking the CAL EventAggregator with Moq

Hi, I'm using the Composite Application Library's event aggregator, and would like to create a mock for the IEventAggregator interface, for use in my unit test. I'm planning on using Moq for this task, and an example test so far looks something like this: var mockEventAggregator = new Mock<IEventAggregator>(); var mockImportantEvent =...

Running unit tests with Nose inside a Python environment such as Autodesk Maya?

I'd like to start creating unit tests for my Maya scripts. These scripts must be run inside the Maya environment and rely on the maya.cmds module namespace. How can I run Nose tests from inside a running environment such as Maya? ...

ExpectedException not catching exception, but I can catch it with try catch

Any ideas on this one? I'm trying to write a unit test that will delete an item and confirm that item is no longer in a repository by trying to retrieve the item by its ID which should throw a DataAccessException. However, the test keeps failing. I added a try catch block and sure enough I caught the exception I was expecting. I'm using ...

Whats the shortest way to assert that an attribute is applied to method in c#?

Whats the shortest way to assert that an attribute is applied to method in c#? I'm using nunit-2.5 :) ...

what is the best location for me to put nunit tests for a library which must be used from both ASP.Net and WinForms

I have an infrastructure library which must be used from both WinForms and ASP.Net. I would like to wrap this up in some unit tests. Which project do I put these in? Do I use another folder in my library project? A different solution which contains only my infrastructure project and a separate unit testing project? Incidentally, I wi...

Watin Tests fail on CC.Net

I'm running Watin tests with xUnit on CC.Net under Windows Server 2003. I have lots of tests that all run fine on development boxes with TestDriven.Net and on the server with the xUnit gui app. However, when CC.Net runs the tests (as part of an MSBuild task) the function ie.ContainsText("some text to find"); never returns the expecte...

After hitting expectedexception test ends

I'm testing the delete method of an abstract base repository class which is inherited by several other repository classes. MyTestRepository inherits the base so I can run tests against the base's methods without restricting my test to using a concrete class. When I run my unit test it passes, but I noticed afterwards I have several Order...

Test Probabilistic Functions

I need a function which returns an array in random order. I want to ensure that it is randomish but I have no idea how one would go about writing the tests to ensure that the array really is random. I can run the code a bunch of times and see if I have the same answer more than once. While collisions are unlikely for large arrays it i...

Can you review my Perl rewrite of Cucumber?

There is a team working on acceptance testing X11 GUI application in our company, and they created a monstrous acceptance testing framework that drives the GUI as well as running scenarios. The framework is written using Perl 5, and scenario files look more like very complex Perl programs (thousands of lines long with procedural-program...

What should I consider when choosing a mocking framework for .Net

There are lots of mocking frameworks out there for .Net some of them have been superseded by others that are better in everyway. However that still leaves many mocking frameworks that have different styles of usage. The time it takes to learn all of them well enough to decide witch to use is unreasonable. I don’t believe that we have ...

Rhino Mocks - How to assert a mocked method was called n-times?

How can i assert that a method on a mocked object was called exactly called n-times? Here is the code snippet from a controller action, i like to test: for (int i = 0; i <= newMatchCommand.NumberOfMatchesToCreate; i++) { serviceFacade.CreateNewMatch("tester", Side.White); } The "service facade" object is the (strict) mock and wil...

How to avoid duplicate logic with Mocks

I have the following challenge, and I haven't found a good answer. I am using a Mocking framework (JMock in this case) to allow unit tests to be isolated from database code. I'm mocking the access to the classes that involve the database logic, and seperately testing the database classes using DBUnit. The problem I'm having is that I'm ...

Mocking methods used in Static Methods [PHPUnit]

I'm trying to stop a method that sends an email from actually sending the email and I think that mock objects (or some variant) are the way to go. Here is the situation: class UserModel { public static function resetPassword() { // Code to generate new password, etc, etc self::_sendMail($to, $body); return 1;...

Tagging unit tests with owner considered a good idea?

I would like to know your opinion on whether it is a good idea to have developers put their name or signature on top of every test they write and why (not)? ...

Python: How to run unittest.main() for all source files in a subdirectory?

I am developing a Python module with several source files, each with its own test class derived from unittest right in the source. Consider the directory structure: dirFoo\ test.py dirBar\ __init__.py Foo.py Bar.py To test either Foo.py or Bar.py, I would add this at the end of the Foo.py and Bar.py so...