unit-testing

How can I test for NSAssert hit cases using iPhone's Unit Testing framework

(Let's assume that I have good reasons not to remove my NSAssert() checks in my code just because I'm also doing Unit testing.) In my unit testing code, I like to make sure that a NSAssert in my code hits (asserts) when I invoke it. I therefore use the STAssertThrows() macro when calling the code that does the assertion. The problem is...

Unit testing - how do I test a function that returns random output?

I have a function which takes in two parameters, and returns one or the other 50% of the time. The unit test for this should determine that both parameters could be returned. Luckily, I don't need to prove that the probability for each is 50% but I do need to show that both parameters are possible to be returned. How do I write a test ...

Django's self.client.login(...) does not work in unit tests

I have created users for my unit tests in two ways: 1) Create a fixture for "auth.user" that looks roughly like this: { "pk": 1, "model": "auth.user", "fields": { "username": "homer", "is_active": 1, "password": "sha1$72cd3$4935449e2cd7efb8b3723fb9958fe3bb100a30f2...

How do I test controllers and views?

I'm using rails for the first time, and I love how test-oriented it is and how it encourages you to write tests. I'm just having a hard time figuring out what I should be testing when I test controllers and views. I know that you should test redirects and authorization in the controller tests, but what else? And what should go in view te...

Run unittest in a Class

Hello, I have a test suite to perform smoke tests. I have all my script stored in various classes but when I try and run the test suite I can't seem to get it working if it is in a class. The code is below: (a class to call the tests) from alltests import SmokeTests class CallTests(SmokeTests): def integration(self): ...

How set EnqueueCallBack to my generic callback

using System; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsistec.Domain; using Microsistec.Client; using Microsoft.VisualStudio.TestTools....

AutoFixture refactoring

I started to use AutoFixture http://autofixture.codeplex.com/ as my unit tests was bloated with a lot of data setup. I was spending more time on seting up the data than to write my unit test. Here's an example of how my initial unit test looks like (example taken from cargo application sample from DDD blue book) [Test] public void shoul...

How do I assert that two arbitrary type objects are equivalent, without requiring them to be equal?

To accomplish this (but failing to do so) I'm reflecting over properties of an expected and actual object and making sure their values are equal. This works as expected as long as their properties are single objects, i.e. not lists, arrays, IEnumerable... If the property is a list of some sort, the test fails (on the Assert.AreEqual(...)...

Microsoft.Silverlight.Testing have an Exectution Order?

I'm trying to perform two methods marked [TestMethod] in an order First: Login Second: GetUser But Test choses the Second to be First. Is there a a way to set order of execution of methods marked [TestMethod]? ...

What is the best testing pattern for checking that parameters are being used properly?

I'm using Rhino Mocks to try to verify that when I call a certain method, that the method in turn will properly group items and then call another method. Something like this: //Arrange var bucketsOfFun = new BucketGame(); var balls = new List<IBall> { new Ball { Color = Color.Red }, ...

How to make efficient code emerge through unit testing ?

Hi, I participate in a TDD Coding Dojo, where we try to practice pure TDD on simple problems. It occured to me however that the code which emerges from the unit tests isn't the most efficient. Now this is fine most of the time, but what if the code usage grows so that efficiency becomes a problem. I love the way the code emerges fro...

Unit testing .Net CF apps on Windows Mobile 6.5.3 in Visual Studio 2008

Did anyone get that to work? I mean, unit testing .Net CF apps on Windows Mobile 6.5.3 in Visual Studio 2008. It works great for a WM 6 Pro target, but not for a WM 6.5.3 target. I get this error: The test adapter ('Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapt...

Guideline on Visual Studio 2008 Unit Test

Is there any guideline on how to use Visual Studio 2008 unit test development? I am developing a n-tier web application using entity framework. My problem is to create Unit Test for the methods which INSERT or UPDATE to the database. ...

Generating JavaScript in C# and subsequent testing

We are currently developing an ASP.NET MVC application which makes heavy use of attribute-based metadata to drive the generation of JavaScript. Below is a sample of the type of methods we are writing: function string GetJavascript<T>(string javascriptPresentationFunctionName, string inputId, ...

ExpectedException on TestMethod Visual Studio 2010

Today I upgraded my solution with all the underlying projects from VS2008 to VS2010. Everything went well except for my unit tests. First of all only the web projects had as target framework .NET 4. All the other projects still had .NET 3.5. I changed them all to .NET 4. Now when I debug my unit tests it breaks on every exception. In 2...

DSL to generate test data

There're several ways to generate data for tests (not only unit tests), for example, Object Mother, builders, etc. Another useful approach is to write test data as plain text: product: Main; prices: 145, 255; Expire: 10-Apr-2011; qty: 2; includes: Sub product: Sub; prices: 145, 255; Expire: 10-Apr-2011; qty: 2 and then parse it into...

How can you create an instance of the System.Management.Automation.ProviderInfo

I'm starting to create a PowerShell Provider. To start off, I have a class inheriting from NavigationCmdletProvider. There's only one protected constructor and it requires an instance of ProviderInfo. Yes, that's ProviderInfo .ctor requiring instance of ProviderInfo. In creating my first test around this provider, I can't seem to find ...

Good tools which generate NUnit unit tests for .NET assemblies in Visual Studio 2008

Hey guys, I'm pretty new to Unit Testing so bear with me. I realize that best best practice is not to auto generate unit tests, however I'd like to use Code Generation to set-up the basic skeleton of the tests. Now, I know Visual Studio 2008 already has the built in "create tests", however, it just creates a flat list of all the classe...

Typical size of unit tests compared to test code

I'm curious what a reasonable / typical value is for the ratio of test code to production code when people are doing TDD. Looking at one component, I have 530 lines of test code for 130 lines of production code. Another component has 1000 lines of test code for 360 lines of production code. So the unit tests are requiring roughly 3x t...

Problem with Authlogic and Unit/Functional Tests in Rails

I'm learning how unit testing is done in Rails, and I've run into a problem involving Authlogic. According to the Documentation there are a few things required to use Authlogic stuff in your tests: test_helper.rb: require "authlogic/test_case" class ActiveSupport::TestCase setup :activate_authlogic end Then in my functional tests...