在JustLock中找不到TestFixtureSetUpAttribute



我正在用C#、.NET Framework 4.7、Nunit 3.8.0和JustLock Lite 2017.2.821.1开发一个TDD测试。

当我这样做时:

IGenericRepository<ProductionOrder> _proOrdRepository = 
Mock.Create<IGenericRepository<ProductionOrder>>();

我得到以下异常:

System.TypeInitializationException occurred
HResult=0x80131534
Message=An exception occurred in the type initializer of 'Telerik.JustMock.Core.Context.MockingContext'.
Source=Telerik.JustMock
StackTrace:
at Telerik.JustMock.Core.Context.MockingContext.get_CurrentRepository()
at Telerik.JustMock.Mock.<>c__44`1.<Create>b__44_0()
at Telerik.JustMock.Core.ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
at Telerik.JustMock.Mock.Create[T]()
at MyProjects.Tests.LoadFinishedTrzlBatchTest.SetUpLoadFinishedTrzlBatch() in D:MyProjectsMyProjectLoadFinishedTrzlBatchTest.cs:line 25
Inner Exception 1:
InvalidOperationException: Some attribute type among NUnit.Framework.TestFixtureSetUpAttribute, nunit.framework,NUnit.Framework.TestFixtureTearDownAttribute, nunit.framework not found.

这是我第一次用TDD和JustMock做一些事情,我不知道如何解决这个问题。

我的测试课程是:

[TestFixture]
class LoadFinishedTrzlBatchTest
{
private LoadFinishedTrzlBatch sut;
private IGenericRepository<ProductionOrder> _proOrdRepository;
[SetUp]
public void SetUpLoadFinishedTrzlBatch()
{
_proOrdRepository = 
Mock.Create<IGenericRepository<ProductionOrder>>();
var batchRepository =
Mock.Create<IGenericRepository<Batch>>();
var codeRepository =
Mock.Create<IGenericRepository<Code>>();
var aggRepository =
Mock.Create<IGenericRepository<Aggregation>>();
var aggChildrenRepository =
Mock.Create<IGenericRepository<AggregationChildren>>();
sut = new LoadFinishedTrzlBatch(
_proOrdRepository,
batchRepository,
codeRepository,
aggRepository,
aggChildrenRepository);
}
[TestCaseSource(nameof(ShouldThrowArgumentSource))]
public void ShouldThrowArgumentExceptionWithInvalidProductionOrderName(string productionOrderName)
{
// Assert
Assert.That(() => sut.ExistsProductionOrder(productionOrderName), Throws.TypeOf<ArgumentNullException>());
}
[Test]
public void ShouldExistsProductionOrder()
{
// Arrange
var productionOrderName = "ProOrd";
var orders = new List<ProductionOrder>() {
new ProductionOrder { Name = productionOrderName },
new ProductionOrder { Name = "Dummy for Filter" }
};
Mock.Arrange(() => _proOrdRepository
.SearchFor(Arg.IsAny<Expression<Func<ProductionOrder, bool>>>()))
.Returns((Expression<Func<ProductionOrder, bool>> expression) =>
orders.Where(expression.Compile()).AsQueryable())
.MustBeCalled();
// Act
var actual = sut.ExistsProductionOrder(productionOrderName);
// Assert
Assert.IsTrue(actual);
}
private static IEnumerable ShouldThrowArgumentSource()
{
yield return string.Empty;
yield return null;
yield return " ";
}
}

知道吗?

更新

我已经删除了方法SetUpLoadFinishedTrzlBatch,并移动了方法ShouldExistsProductionOrder中的所有内容,我得到了相同的错误。

[Test]
public void ShouldExistsProductionOrder()
{
LoadFinishedTrzlBatch sut;
IGenericRepository<ProductionOrder> _proOrdRepository;
_proOrdRepository =
Mock.Create<IGenericRepository<ProductionOrder>>();
var batchRepository =
Mock.Create<IGenericRepository<Batch>>();
var codeRepository =
Mock.Create<IGenericRepository<Code>>();
var aggRepository =
Mock.Create<IGenericRepository<Aggregation>>();
var aggChildrenRepository =
Mock.Create<IGenericRepository<AggregationChildren>>();
sut = new LoadFinishedTrzlBatch(
_proOrdRepository,
batchRepository,
codeRepository,
aggRepository,
aggChildrenRepository);
// Arrange
var productionOrderName = "ProOrd";
var orders = new List<ProductionOrder>() {
new ProductionOrder { Name = productionOrderName },
new ProductionOrder { Name = "Dummy for Filter" }
};
Mock.Arrange(() => _proOrdRepository
.SearchFor(Arg.IsAny<Expression<Func<ProductionOrder, bool>>>()))
.Returns((Expression<Func<ProductionOrder, bool>> expression) =>
orders.Where(expression.Compile()).AsQueryable())
.MustBeCalled();
// Act
var actual = sut.ExistsProductionOrder(productionOrderName);
// Assert
Assert.IsTrue(actual);
}

我认为问题出在JustLock。

JustLock依赖于NUnit 3和NUnit 2的TestFixtureSetUpAttribute和TestFixtureTearDownAttribute。

这两个属性在NUnit 3.0中被弃用,在NUnit 3.8中刚刚被删除。JustLock应该更新以使用它们的替换OneTimeSetUpOneTimeTearDown

作为用户,在解决此问题之前,您不能使用NUnit 3.7.1之后的版本。您可以在此处向JustLock报告此问题。

自JustLock 2018 R1发布以来,该问题已得到修复。

为了进一步更新,JustLock(Version-2017.3.913.1(现在支持3.7.1版本的NUnit,但它仍然存在于3.8.x版本。

如果您可以灵活地降级NUnit的版本,可以执行以下操作。

1:在VS中,转到-工具>NuGet包管理器>包管理器控制台。

2:PM>Install Package NUnit-Version[较低版本](只需在-Version后按tab键即可获得所有支持的版本(,您就可以降级NUnit版本。

相关内容

  • 没有找到相关文章

最新更新