【问题标题】:Can we unit test ApplicationInstaller in c#?我们可以在 C# 中对 ApplicationInstaller 进行单元测试吗?
【发布时间】:2013-01-16 13:19:08
【问题描述】:

我正在做单元测试。现在我是单元测试的新手。我正在使用带有 mvc3 框架的 nunit 和 rhino mock。我应该对 ApplicationInstaller.cs 进行单元测试吗?请为我推荐一些用于 nunit 测试的推荐读物。

public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
{
    container.Register(
        AllTypes.FromAssemblyContaining<IEmployeeModelAssembler>()
        .Where(x => x.Name.EndsWith("Assembler"))
        .WithService.DefaultInterfaces());

    container.AddFacility<LoggingFacility>(x => x.LogUsing(LoggerImplementation.Log4net).WithConfig("log4net.config"));

    container.Register(
        // All controllers
        AllTypes.FromAssembly(Assembly.GetExecutingAssembly()).BasedOn<IController>().LifestyleTransient(),
        //
        Component.For<IControllerFactory>().ImplementedBy<IoCControllerFactory>(),
        Component.For<ICookieManager>().ImplementedBy<CookieManager>().LifeStyle.Is(LifestyleType.Transient),
        Component.For<IJsonSerializer>().ImplementedBy<JsonSerializer>(),
        Component.For<ILoanActionsUtility>().ImplementedBy<LoanActionsUtility>(),
        // Default D.I. container
        Component.For<IWindsorContainer>().Instance(container));

    // Register AES web services
    container.Install(new AESServicesBootstrapper.ApplicationInstaller());

}

#endregion

/// <summary>
/// Creates a WCF client for web services passing the token of the authenticated user from the cookie.
/// This method only creates the client / channel, it does not configure the connection settings,
/// those have to be defined by named endpoints on the web.config
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="endPointConfiguration">name of the endpoint on the web.config</param>
/// <returns></returns>

}

【问题讨论】:

  • 你能让你的标题和问题一致吗? “我们可以……”和“我们应该……”这两个问题是不同的(当然,如果第一个问题的答案是“否”,那么第二个问题就没有实际意义了)

标签: c# asp.net-mvc-3 nunit


【解决方案1】:

根据我的经验,测试上面的代码没有多大价值。它基本上是配置,没有任何决策,因此您的测试只能确保应用程序按照您想要的方式进行配置。这基本上是您上面代码的重复。

如果您的安装程序中发生了逻辑,那么您可能需要围绕它进行一些测试。如果事情开始因大量逻辑而失控,那么您正在研究将该代码删除到另一个类中的领域,甚至不将其包含在您的安装程序代码中。

您可能会在Programmers 上遇到这些类型的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-06
    • 2010-09-22
    • 1970-01-01
    • 2019-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多