Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 634115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:15:31+00:00 2026-05-13T20:15:31+00:00

After all what I have read about Dependency Injection and IoC I have decided

  • 0

After all what I have read about Dependency Injection and IoC I have decided to try to use Windsor Container within our application (it’s a 50K LOC multi-layer web app, so I hope it’s not an overkill there). I have used a simple static class for wrapping the container and I initialize it when starting the app, which works quite fine for now.

My question is about unit testing. I know that DI is going to make my life much easier there by giving me the possibility of injecting stub / mock implementations of class collaborators to the class under test. I have already written a couple of tests using this technique and it seems to make sense for me. What I am not sure about is whether I should be using IoC (in this case Windsor Castle) also in unit tests (probably somehow configure it to return stubs / mocks for my special cases) or is it better to wire-up all the dependencies manually in the tests. What do you think and what practice has worked for you ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:15:31+00:00Added an answer on May 13, 2026 at 8:15 pm

    You don’t need DI container in unit tests because dependencies are provided through mock objects generated with frameworks such as Rhino Mocks or Moq. So for example when you are testing a class that has a dependency on some interface this dependency is usually provided through constructor injection.

    public class SomeClassToTest
    {
        private readonly ISomeDependentObject _dep;
        public SomeClassToTest(ISomeDependentObject dep)
        {
            _dep = dep;
        }
    
        public int SomeMethodToTest()
        {
            return _dep.Method1() + _dep.Method2();
        }
    }
    

    In your application you will use a DI framework to pass some real implementation of ISomeDependentObject in the constructor which could itself have dependencies on other objects while in a unit test you create a mock object because you only want to test this class in isolation. Example with Rhino Mocks:

    [TestMethod]
    public void SomeClassToTest_SomeMethodToTest()
    {
        // arrange
        var depStub = MockRepository.CreateStub<ISomeDependentObject>();
        var sut = new SomeClassToTest(depStub);
        depStub.Stub(x => x.Method1()).Return(1);
        depStub.Stub(x => x.Method2()).Return(2);
    
        // act
        var actual = sut.SomeMethodToTest();
    
        // assert
        Assert.AreEqual(3, actual);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read all these articles about how to make system.web.routing work but all
I have read a few articles about how to programmatically interacting with Active Directory.
Good day folks I must have read about 20 different articles/approaches about how to
Hey there, I have read the few posts here on when/how to use the
I have read the other posts about the notorious _imaging C module error when
Ok, I have read a lot of posts and resources about this but I
Even after all the hotfixes and updates that are supposed to fix this, my
What to do when after all probing, a reportedly valid object return 'undefined' for
It's gotta be free. It's hobby, after all, not a business!. Creating for-profit software
I don't know if I should test my @Entity-annotated Pojos. After all, there are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.