unit-testing

SenTestKit: cleaning up after ALL tests have run?

I am using SenTest in XCode for my unit tests. I must run a command-line task for my unit tests to test. I can do that in the +initialize method of my test class (subclass of SenTestCase, of course). I would like to terminate the command-line task when the tests are done. Since there's not an opposite of +initialize, I'm stumped. Is th...

How to mock arbitrary behavior with Rhino Mocks?

Hi all, I'm trying to mock a data layer method. The method takes a string and two lists as arguments, and the method populates those lists from the results of a stored proc. Also, I'm still on C# 2.0 with VS2005, and I'm using Rhino Mocks 3.5 for .NET 2.0. If possible, it would be nice to use the AAA format. So yeah, all I want to do ...

How to handle setting up complex unit test and have them only test the unit

I have a method that takes 5 parameters. This method is used to take a bunch of gathered information and send it to my server. I am writing a unit test for this method, but I am hitting a bit of a snag. Several of the parameters are Lists<> of classes that take some doing to setup correctly. I have methods that set them up correctly ...

Good book on testing for a dev?

Hi, As a developer, we are required to test our code to some extent to find bugs (destructive/negative testing mainly, and unit tests). What is a good book that covers the level of testing a developer has to do and the best way to do it/best practises? The book can briefly list the types of testing a dev doesn't usually do (e.g. load te...

How can I trigger a native Javascript event from a QUnit test?

I'm working on a Javascript library that does not depend on jQuery, though I have jQuery and QUnit available in my tests. In the library, I attach an event to an element the way jQuery does: if (document.addEventListener) { tab.addEventListener('click', MyModule.show, false); } else if (document.attachEvent) { tab.attachEvent('click...

Ruby on Rails: Unable to assign attributes to models built in unit tests

I'm trying to test creation of a new model inside my unit tests, and I'm getting some puzzling behavior. In this example, I already have a fixture that define an Article :valid_article: public_review = Review.new({:article => articles(:valid_article)}) assert !public_review.article_id.nil? Oddly enough, this fails the assertion, beca...

How to mock HttpClientCertificate?

I am trying to unit test an action filter I wrote. I want to mock the HttpClientCertificate but when I use MOQ I get exception. HttpClientCertificate doesnt have a public default constructor. code: //Stub HttpClientCertificate </br> var certMock = new Mock<HttpClientCertificate>(); HttpClientCertificate clientCertificate = certMock.Obj...

Mocking ref parameters

I've cross posted this on the #moq discussion group at: http://groups.google.com/group/moqdisc/browse_thread/thread/569b75fd2cc1829d hey folks, I have come across a problem with a mocked ref param that I'm sure must be obvious, but being new to the framework I just can't work it out. I have the following repository method: public int...

Tests for more inputs

Hi, I'm using MSTest for testing and when I want to apply more inputs then the test looks like this: [TestMethod] public void SumTest() { // data to test var items = new [] { new { First = 1, Second = 1, Expected = 2 }, new { First = -1, Second = 1, Expected = 0 }, new { First = 1, Second = 2, Expected = 3 }, new { ...

How can I exclude lambda functions in properties from code coverage?

I am trying to gather some good code coverage stats for my C# application, but I would like to ignore the generated SubSonic classes as there is no real point in gathering code coverage statistics for these functions. I have edited the ActiveRecord.tt file to include the [ExcludeFromCodeCoverage] attribute on every method and property, ...

Mocking LINQ To SQL data provider, NotSupportedException on Live code

Yet another "simple" question about unit testing model objects that uses data access layer. When I mock my Table<Customer> to IQuerable<ICustomer>, where new List<FakeCustomer>().AsQuerable() is used in role of in memory data store, the following code passes unit test perfectly: var filteredCustomers = from c in dal.Customers ...

Outsourcing unit development

As a freelancer, if you are working on a project, and if you outsource the development of a unit or a small component - would it be ethical to do this given that the client is not aware that some development is being developed by a third party? ...

How to unit-test an internet protocol implementation?

I decided to add unit tests to my project and continue development in a test-driven kind of way. I’m currently working on implementing unit tests for my ManageSieve client object and I’m not sure what’s the best way to test that beast. My SieveClient object relies on two other objects for the network communication: CocoaAsyncSocket and ...

Good examples of Android projects covered by tests?

Could you point some good examples of Android projects that have unit testing in action? It would be great to learn by example from those. ...

Accessing child attributes from parent Factory Girl factories

I'm implementing Factory Girl as a replacement for fixtures in my Rails app. I have several tables that I'm trying to represent using associations. However, to throw a kink into the loop, beyond just defining the associations, I also need to access attributes of the child factories from the parent. Below is an example of what I'm tryi...

Python "ImportError: No module named" Problem

I'm running Python 2.6.1 on Windows XP SP3. My IDE is PyCharm 1.0-Beta 2 build PY-96.1055. I'm storing my .py files in a directory named "src"; it has an __init__.py file that's empty except for an "__author__" attribute at the top. One of them is called Matrix.py: #!/usr/bin/env python """ "Core Python Programming" chapter 6. A si...

Clearing Entire Database (for unit testing with Hibernate)

My unit tests use Hibernate to connect to an in-memory HSQLDB database. I was hoping there would be a way to clear and recreate the database (the entire database including the schema and all the data) in JUnit's TestCase.setUp() method. ...

Django test runner runs 0 tests...

Hi all, I have a problem similar to what's described here, but the problem's not related to not having installed sites or apps (all other management commands work fine anyway). I've used the standard tests.py that comes under my app's directory just to check everything, and I get the complete "creating table..." and "Installing index....

Why does ObjectContext class not derive from some Interface ?

I consider folks at MS way more smarter than I am. I was trying to build/test a repository which almost follows this approach except that I want to loosely couple the ObjectContext dependency inside the repository. I found out that in order to do decouple this I need to jump a lot of hoops as shown in this article.Even this approach is d...

Unit Testing WCF Authentication and ServiceContext

Hi guys, I have some methods that has RequireAuthentication and RequiresRole attribute and some methods that require authenticated user's identity (Which i will get from ServiceContext.User.Identity). How can I unit test these kind of methods? Thanks. ...