从Kentico 9更新到Kentico 10后,单元测试不再有效

时间:2016-12-20 10:02:45

标签: unit-testing kentico

从Kentico 9更新到Kentico 10后,我的单元测试不再有效。

我有这样的UnitTest。 (在Kentico 9上工作正常)

    [SetUp]
    public void setUp()
    {
        this.pageCreator = new PageCreator();
        this.fixture = new Fixture();
        this.fixture.Customize(new AutoMoqCustomization());
    }
     [Test]
    public void execute()
    {
        this.pageCreator.Execute(null);
    }

我只是试着调用这个函数

 public class PageCreator : ITask
 {
  public string Execute(TaskInfo task)
    {
        try
        {
            this.treeProvider = new TreeProvider(MembershipContext.AuthenticatedUser);
            this.createPages(this.treeProvider);

            return successMessage;
        }
        catch (Exception ex)
        {
            this.sendMailToDeveloper(ex.Message);
            return "Fail";
        }

问题是,当我尝试运行我的测试时,我得到一个错误(因为MembershipContext.AuthenticatedUser [ CMS.Membership.MembershipContext.AuthenticatedUser " hat eine Ausnahme vom Typ&# 34; System.InvalidOperationException " verursacht])

enter image description here

当我尝试在debugMode中做同样的事情时,一切正常。

enter image description here

可能是什么问题以及如何解决?
我从Kentico 10加载了所有新的Dll,但没有任何改变。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

尝试更新测试项目的参考资料,以使用Kentico10 nuget软件包。发行说明中有一节关于自动化测试 - https://docs.kentico.com/k10/release-notes-kentico-10

"自动化测试 - 新的Kentico.Libraries.Tests集成包,它单独提供与Kentico API自动测试相关的所有功能。测试API不再直接在Kentico项目或主要的Kentico.Libraries集成包中提供。"