unit-testing

Why should I test my HTMLHelpers?

Is there any tangible value in unit testing your own htmlhelpers? Many of these things just spit out a bunch of html markup - there's little if no logic. So, do you just compare one big html string to another? I mean, some of these thing require you to look at the generated markup in a browser to verify it's the output you want. Seems a...

How slow is too slow for unit tests?

Michael Feathers, in Working Effectively With Legacy Code, on pages 13-14 mentions: A unit test that takes 1/10th of a second to run is a slow unit test... If [unit tests] don't run fast, they aren't unit tests. I can understand why 1/10th a second is too slow if one has 30,000 tests, as it would take close to an hour to run....

Why does Dispatcher.Invoke not execute the delegate argument in this example ?

[Test] public void A() { var d = Dispatcher.CurrentDispatcher; Action action = () => Console.WriteLine("Dispatcher invoked me!"); var worker = new BackgroundWorker(); worker.DoWork += SomeWork; //worker.RunWorkerAsync( (Action) delegate { Console.WriteLine("This works!"); } ); ...

How to unit-test private code without refactoring to separate class?

Assume i have a private routine that performs some calculation: private function TCar.Speed: float { Result = m_furlogs * 23; } But now i want to begin testing this calculation more thoroughly, so i refactor it out to a separate function: public function TCar.Speed: float { Result = CalculateSpeed(m_furlogs); } private functio...

Where is EnqueueDelay method call in silverlight unit testing?

I have created a silverllight unit test page and it has the reference to both Silverlight.Testing and ...UnitTesting.Silverlight. I have reference to both of them in my test project as using as well. When I tried to do EnqueueDelay(1000), VS does not recoganise this as a valid method call. What am I doing wrong? Thanks, ...

Why expected exception does not catch the expection thrown in the code as success in VSTest?

I tried to run the example from the following link http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.expectedexceptionattribute.aspx expecting the test to pass, but the test is failing with the same error. Is there something I am missing? Thanks, ...

Selenium, Using multiple firefoxProfileTemplates at once / specifying from selenium object rather than at server launch?

I am using Selenium RC for website testing and I need to use multiple proxies at once and am doing this using: firefoxProfileTemplate when I start the selenium server. This, however, doesn't allow me to multi-thread selenium as each selenium object still uses the same firefoxProfileTemplate, and therefore the same proxy, (I am using Pyth...

Run JavaScript unit tests inside of Visual Studio 2010

I have been searching for a good way to run JavaScript unit tests inside of the Visual Studio 2010 IDE. I currently use TestDriven.net to run my C# units tests and it is very convenient to be able to quickly get the result of my tests in the output pane. I would love to find a similar experience for JavaScript (ideally working with Test...

Unit testing controllers with annotations

Hi there, I'm trying to write some unit tests for my controllers in a Spring MVC web app. I have already got a fairly comprehensive set of unit tests for the domain model, but for completeness I want to test the controllers too. The issue I'm facing is trying to test them without loading a Spring context. I thought I could get around...

Designing unit tests for XML documents

I have a following method which takes a XDocument, iterates through the nodes and remove/replace nodes based on some condition. public static void Format(XDocument xDocument) { foreach(XmlNode documentNode in xDocument) { XmlNode[] spanNodes =documentNode.SelectNodes("//span") ; foreach(XmlNode spanNode in span...

MS UnitTest - Private Accesor not always recognized

This problem doesnt occur in all projects, hence it makes it even more frustrating. If I click on a Private method to create a unit test, it would generate a TestProject assembly and create a predefined class in there. It woudl also create a Accessor for that class. [TestMethod()] [DeploymentItem("xxx.Client.dll")] pub...

How do I mock sleep() in a groovy unit test case?

I have to unit test a method of a groovy class which uses sleep() to delay processing in a loop. Obviously I don't want my test suite to sleep really, so I tried to mock the sleep() call in my class: MyClass.metaClass.sleep = { return } I tried a few variations of this with no success. Can someone tell me the correct way to mock thi...

Test deployment failed for indirect reference assembly not found, Visual Studio 2008

Hello, I am new to unit testing. I was trying to run a simple unit test in Visual Studio 2008. The code I was testing uses a third party library. When I try to run the test, following error occurred. "Warning: Test Run deployment issue: The assembly or module 'nunit.framework' directly or indirectly referenced by the test container ......

Assert that a method was called in a Python unit test

Suppose I have the following code in a Python unit test: aw = aps.Request("nv1") aw2 = aps.Request("nv2", aw) Is there an easy way to assert that a particular method (in my case aw.Clear()) was called during the second line of the test? e.g. is there something like this: #pseudocode: assertMethodIsCalled(aw.Clear, lambda: aps.Request...

Best way to change the value of "settings" from within a Python test case?

I'm writing unit tests in Python for the first time, for a Django app. I've struck a problem. In order to test a particular piece of functionality, I need to change the value of one of the app's settings. Here's my first attempt: def test_in_list(self): mango.settings.META_LISTS = ('tags',) tags = Document(filepath).meta['tags']...

Unit test error (JSF): Absent Code attribute in method that is not native or abstract

Hello! I get a strange error when Im trying to unit test a Java class dealing with JSF components (javax.faces.model.SelectItem). The error I get is this: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/model/SelectItem at java.lang.ClassLoader.defineClass1(Na...

surefire forkMode causes only last test to be recorded in TestSuite.txt

I have the following in my pom.xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.6</version> <configuration> <excludes> <!-- exclude integration tests --> <exclude>**/IT*.j...

C++ Program quits unexpectedly, how do I debug this with gdb?

Hi Everyone, I am writing a program that runs some unit tests on code that that been written by my colleagues. I am using the Google C++ testing framework. I run a function that spawns 3 threads, and then runs for 30 seconds. After it runs, the program exits with status 0. This is not the expected behavior, obviously. I know it doesn't ...

How to avoid false positives using a mockist approach in unit tests?

Since the datastructure of my application domain is becoming pretty complex as of late, I started reading up on mock objects. Soon a simple question came to my mind, but the answer has proven to be quite the headache so far. So here goes: We have a class 'Foo' with 'bar' as one of its methods: class Foo { public String bar(int i){ ...

Are there any issues I should know about with unit test of Windows 7 Phone code?

I am assuming that as the code is standard C#, I can just use nUnit, TestDriven.net etc. Have I missed something? What “traps” have other people hit trying to do this? ...