我有多个单独的测试类,它们都使用相同的测试对象。目前我在每个类中都使用 @Before,这显然不是一个很好的解决方案。
当然,一种选择是从创建此对象的抽象类继承。正如此处所述,这也不是一个好主意。
另一种选择是外部资源,但正如名称所说,用于资源而不是测试对象。
我觉得我错过了一些东西,因为这必须是 JUnit 中的一项基本任务。
我有一个对象,其中包含一个具有另一个对象类型的属性,我想将其视为复杂类型。
public class Location : IModule
{
public string Id { get; set; }
public Coordinate Coordinate { get; set; }
}
[ComplexType]
public class Coordinate
{
public string Latitude { get; set; }
public string Longitude { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在添加迁移时,我遇到了需要主键的问题(正是我想要防止的)。
实体类型Coordinate需要定义一个主键。
编辑
出于性能原因,我希望将属性存储为Coordinate_Latitude而Coordinate_Longitute不是引用另一个表。