unit-testing

How to include inside method

I don`t want to use the [ExpectedException(ExceptionType = typeof(Exception), ExpectedMessage = "")] instead would like to include the exception inside my method. Can I do that? Any example please. Thanks ...

How to unit-test IBOutlet connections ?

I've been trying to verify in my tests (GTM) that when a nib file is loaded, its IBOutlets were properly connected in InterfaceBuilder. However I keep getting nil references, despite calling [myViewController viewDidLoad] before asserting that the reference should exist. Are there any gotchas here, or should this be mocked somehow ? c...

JBoss Arquillian integration with Apache Ant and Junit

Has anyone managed to integrate Arquillian with Ant and JUnit? If so, could you provide an example? ...

javascript: How do I verify timer properties?

If I have the following code: var myfunc = function() { alert('wow'); }; var t=setTimeout(myfunc, 300); Is there anything I can do with the id stored in t to verify the timer's duration and callback? I'm trying to verify the timer's properties directly so I don't have to actually run it 'till timeout in my unit tests. ...

Exception not tested with phpUnit?

Hi, I'm writing some unit test with phpUnit to test a Zend Framework application and I've got some issues with testing an exception in the changePassword function. The test doesn't fail, but in the coverage tool which generates html the "throw new Exception($tr->translate('userOldPasswordIncorrect'));" line isn't tested. public functio...

Unit-testing - how to start with it?

Hi there, at the moment I'm developing in a more "uncool" kind: I write my stuff and see if this works with manual interaction. (For the most time I'm writing java based webapps) I know that unit-testing would cut some of the bugs I meet in devtime but to be honest: I dont know how go with unittesting. Especially I don't really have a ...

Unit-Tests organization

I currently am using the following bit of code to initialize some Unit-Tests in a class: [TestClass] public class BoardTests_SquarePieceFalling { private Engine engine; private BackgroundBoard backgroundBoard; private PieceBoard pieceBoard; private IFallingPieceFactory GetFallingPieceFactory(FallingPiece fallingPieceToR...

how thorough should a unit test be?

To unit test the method doSomething(String name) in ClassA below, what things should I test on the return value? My first thought is to test that the name attribute is set properly on Wrapper that the formattedName attribute on Wrapper is properly formatted But on second thought, should I instead test the value of formattedName ...

Is it possible to host the clientaccesspolicy.xml file with the ASP.NET Development Server?

I have a solution with two service projects (one is hosting a unit test silverlight application and other is providing the services being tested). Because of cross-domain policy, I have to publish the primary service site to IIS before the unit test site can consume a service. Is it possible to host the clientaccesspolicy.xml file on A...

Need a C# example of unintended consequences

I am putting together a presentation on the benefits of Unit Testing and I would like a simple example of unintended consequences: Changing code in one class that breaks functionality in another class. Can someone suggest a simple, easy to explain an example of this? My plan is to write unit tests around this functionality to demonst...

Mocking a session wrapper in MVC2

I've seen how to Fake the SessionState object in MVC using Scott Hanselmans MvcMockHelpers, but I'm dealing with a separate problem. What I like to do is create a wrapper around the Session object to make objects a little more accessible and strongly typed rather than using keys all over. Here is basically what it does: public class S...

Unit-Testing delegating methods

Is there any point in Unit-Testing a method that the only thing it does is delegate work on another object? Example: class abc { ... public void MoveLeft() { fallingPiece.MoveLeft(); } ... } I am doing Unit-Tests for some existing classes I have, for learning purposes. It seems kinda odd to do a Unit-Tes...

Visual Studio and NUnit - automatic running of unit tests on build

I would love to know if there is a way I can get Visual Studio to run unit tests corresponding to a given assembly whenever I build it. Given a solution containing projects structured like this: Assembly1 Assembly1.Tests Assembly2 Assembly2.Tests Is there a way I can get the unit tests in Assembly2.Tests to run whenever Assembly...

How can I make HttpContext available to be used by my Unit Tests?

Hi, I want to write a unit test which tests the function of a class called UploadedFile. The problem I face is this class' static constructor uses HttpContext.Current property and because I am running my unit test from a class library I do not have an HttpContext at the testing time. Look at my static constructor: static UploadedFil...

(Deep) comparison of an object to a reference in unit tests (C#)

Hi all, In a Unit Test (in Visual Studio 2008) I want to compare the content of a large object (a list of custom types, to be precise) with a stored reference of this object. The goal is to make sure, that any later refactorings of the code produces the same object content. Discarded Idea: A first thought was to serialize to XML, and t...

Integration tests and TDD

I have this first integration test for a tic tac toe game: [TestClass] public class FirstIntegrationTest { [TestMethod, TestCategory("Integration Tests")] public void Standard_TicTacToe_Game_PlayerO_Wins() { IPlayer playerO = new Player(); IPlayer playerX = new Player(); Game game = new Game(playerO,...

Can unit testing be successfully added into an existing production project? If so, how and is it worth it?

I'm strongly considering adding unit testing to an existing project that is in production. It was started 18 months ago before I could really see any benefit of TDD (face palm), so now it's a rather large solution with a number of projects and I haven't the foggiest idea where to start in adding unit tests. What's making me consider this...

.NET version of Java's assertGC: Unit tesing memory leaks

I am trying to write a unit test using .NET 4 to ensure that an object can be garbage collected after some code is run. In Java, I would use assertGC to ensure that a weak reference is collected. How can I write this type of test for .NET? I have tried keeping a WeakReference to the object and calling GC.Collect(), but as you'd expect, ...

Pointers for writing a unit test for a Razor based View needed.

I'm trying out the new Razor view engine with MVC 3 Preview 1 and would really like to write a simple unit test using NUnit/Moq. I haven't seen any examples of this actually being done yet - despite it being one of the real selling features on Razor. So, if I have a Controller, that uses a DBConext object (EF4 CTP code first) and the vi...

Debugger runs only once per IDE startup.

Hi there, I have been using MS VS2010 debugger for quite some time now and didn't came across any problems untill today. As a tester I start my debugger in testing mode (single test debugging) right after loading the project and it starts a whole batch of tests written. Despite starting all the tests the debugger itself works properly...