使用 'uses' 进行单元测试 mapstruct
Unit testing mapstruct with 'uses'
使用 spring 引导时,是否有单元测试映射器的标准方法?即获取依赖项等
我目前正在做这样的事情:
@SpringBootTest(classes = {VehicleMapper.class, VehicleMapperImpl.class,
VehicleAttributesMapper.class, VehicleAttributesMapperImpl.class})
@RunWith(SpringRunner.class)
public class VehicleMapperTest {
@Autowired
private VehicleMapper vehicleMapper;
VehicleMapper 用途:
@Mapper(componentModel = "spring", uses = VehicleAttributesMapper.class)
然而,当我 运行 我的单元测试时 VehicleAttributesMapper
似乎没有被调用? (类型匹配,即 source/target)
TIA
原来我需要在 VehicleMapper 中添加一个显式映射:
@Mapping(source = "vehicleInfo", target = "vehicleAttributes")
我原以为这不需要明确地完成。在 docs 下的“Invoking other mappers”中,它似乎建议您不要(无论如何在示例中)。
使用 spring 引导时,是否有单元测试映射器的标准方法?即获取依赖项等
我目前正在做这样的事情:
@SpringBootTest(classes = {VehicleMapper.class, VehicleMapperImpl.class,
VehicleAttributesMapper.class, VehicleAttributesMapperImpl.class})
@RunWith(SpringRunner.class)
public class VehicleMapperTest {
@Autowired
private VehicleMapper vehicleMapper;
VehicleMapper 用途:
@Mapper(componentModel = "spring", uses = VehicleAttributesMapper.class)
然而,当我 运行 我的单元测试时 VehicleAttributesMapper
似乎没有被调用? (类型匹配,即 source/target)
TIA
原来我需要在 VehicleMapper 中添加一个显式映射:
@Mapping(source = "vehicleInfo", target = "vehicleAttributes")
我原以为这不需要明确地完成。在 docs 下的“Invoking other mappers”中,它似乎建议您不要(无论如何在示例中)。