检查单元测试是否为ABP的测试模式(ShouldInitializedApplication),如下所示:
[Fact] // or [TestMethod] in MSTest
public async Task Should_Get_HelloWorld_Title()
{
//Arrange
using (var scope = _fixture.CreateScope())
{
//Act
var helloWorldTitle = await scope.ServiceProvider.GetService
如果不是ABP测试模式,可以为测试添加以下代码以手动初始化ABP应用程序:
public MyProjectTestModule() { ConfigureServices(ConfigureServices); }
private void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddApplication
并在测试类上添加以下属性:
[CollectionDefinition(Name = nameof(MyProjectTestModuleCollection))]
public class MyProjectTestModuleCollection : ICollectionFixture
这样,ABP本地化资源就能在单元测试中按预期工作了。