unit-testing

How can I write a unit test to determine whether an object can be garbage collected ?

In relation to my previous question, I need to check whether a component that will be instantiated by Castle Windsor, can be garbage collected after my code has finished using it. I have tried the suggestion in the answers from the previous question, but it does not seem to work as expected, at least for my code. So I would like to write...

Unit Testing Mere Mortals .NET Framework

Assuming a client already has chosen to use the Mere Mortals Framework from Oak Leaf Software, what would be the recommended approach to allow for unit testing and proper separation of concerns for the resulting application? Ideally I'd like to achieve something like SOLID design principles and have layers that are not all completely co...

Removing dependancies when unit testing procedural code

In an object-oriented language with inheritence and virtual functions, removing dependancies (e.g. database, API calls, etc) from your unit testing code can be as simple as encapsulating those dependancies in their own methods and then overriding those methods in a test class inheriting from the class to be tested. However, I've run int...

Unit Tests for external projects

Hi, I'm trying to get a concensus of what people do with regard to unit tests and sub (or external) projects. I'll, hopefully, clarify with an example. I have a project P1 that relies on another project P2. P2 has its own unit tests and release cycle. P1 has its own unit tests as well. The question is should the unit tests for P2 be...

What is the Best Practice to manage older unit test when you're debugging or adding a new feature?

Hi Guys, I'm trying to understand what's the best way to manage older unit test that doesn't really match or works anymore due to reason like bugs or logic changes in your code? Do we just skip them all by and modify them to fit the current logic? For example if those tests weren't written by you, and now you're in charge to modify the ...

Why does this unit test pass in Visual Studio 2005 but fail in VS2008?

[TestMethod] [ExpectedException(typeof(FormatException))] public void PassGodammit() { throw new FormatException(); } ?? driving me mad. ...

New to Unit Testing

I would like to know how to implement unit testing in an existing (quite large) application using visual studio 2008 (.net 2.0). I understand that developing unit tests for the existing/legacy code is not realistic but I would like to have tests for code moving forward. I have found plenty of examples on how to write tests for code but...

Uses for the adapter pattern (with 3d party libraries)

Hi, In reference to an earlier question of mine link text, I have been searching for good ways to write code that is very dependant on 3d party libraries, but still unit-testable. Just to sketch the contest (so you don't have to read the previous post), I am writing code with the AutoCAD API. This way my code is very dependant on that ...

Is there a way to get a test results and coverage html report from MSTest

I'd like to be able to produce a HTML based report from the Results.trx and data.coverage files that MSTest creates. Ideally this would just list any failures, and show some basic coverage stats. Does anyone know of a tool that does this? ...

Introducing unit testing to a wary team

I've seen similar questions around "How can I start with unit testing?" and I believe I've even run across a couple that ask how to best introduce it to the team. IIRC, the responses were mostly to the tune of "if you build it, they will come"...meaning once others see what you're doing with it, they'll start using it too. While I'm defi...

nunit setup/teardown not working?

Ok, I've got a strange problem. I am testing a usercontrol and have code like this: [TestFixture] public myTestClass : UserControl { MyControl m_Control; [Test] public void TestMyControl() { m_Control = new MyControl(); this.Controls.Add(m_Control); Assert.That(/*SomethingOrOther*/) } } Th...

How do you get a #if conditional to work when unit testing?

this is what I would like to be able to do. /// <summary> /// Gets the session factory. /// </summary> /// <value>The session factory.</value> public ISessionFactory SessionFactory { get { if (_sessionFactory == null) { #if(NUNIT) ...

How do I mock a private field?

I'm really new to mocks and am trying to replace a private field with a mock object. Currently the instance of the private field is created in the constructor. My code looks like... public class Cache { private ISnapshot _lastest_snapshot; public ISnapshot LatestSnapshot { get { return this._lastest_snapshot; } ...

How do I stub the HttpSessionState in MVC RC1 with rhino mocks?

I'm trying to take advantage of the recent ControllerContext refactoring in asp.net mvc rc1. I should be able to stub the session rather simply but I keep getting a System.NullReferenceException on line 2 when running the following code: var mockContext = MockRepository.GenerateStub<ControllerContext>(); mockContext.Stub(x => x.HttpCont...

unit testing user login/logout

I am very new to the whole unit testing concept so I'm sorry if "unit test" is the wrong word for this. I think it might actually be a "integration test"? At any rate, I am using asp.net's membership framework for login, logout, change password, etc. But I do a few extra things like updating the authentication ticket, adding an entry to...

VS2008 - benefit of running Unit Tests for a CF Library on an emulator?

When using the VS2008 unit testing framework, I see the testrunConfig has an option to set the Host. If I change the Host from "Smart Device" to "Default" it appears like I can run the tests without deploying to an emulator. I am wanting to test a library built for use on the Compact Framework, but it has nothing to do with the UI, etc....

Returning mock objects from factory girl

I am using Mocha and Factory_girl in a JRuby rails application. When I call the factory I would like to return the objects with some mocking already done. Here is a code snippet of what I am trying to do. Factory.define :tweet_feed_with_tweets, :parent => :tweet_feed do |t| t.expects(:pull_tweets).returns([Factory.build(:status),Fac...

passing test.includes into intellij idea test runner parameters

for example, in ant i would use something like fileset dir="src/tests" includes="${test.includes}" excludes="${test.excludes}"/> in the junit task. there is a Test Runner Parameters field in the Run Configurations in Intellij, but i cant seem to find how to pass that sort of information in. basic use case: i have abstract tests which...

Unit testing custom StyleCop rules

I'm wondering what's the best way to go about unit testing custom SytleCop rules. I've read this but am hoping there's a better solution. Thanks. ...

What attribute should a good Unit-Test have?

A Unit-Test should produce deterministic result be independent be valid ... What other characteristics should a test also have? ...