我创建了一个模拟测试,用于测试插入到mongodb数据库中。我想知道如何验证单元测试。方法插入返回一个空值。那么我该如何验证?另外,某些方法不会返回void。我该如何验证呢?
@Repository
public class DataDao<T> implements {
@Autowired
private MongoOperations mongoOps;
public DataDao(MongoOperations mongoOps) {
this.mongoOps = mongoOps;
}
@Override
public void insert(Class<T> t, List<T> t1) {
this.mongoOps.insert(t1, t);
}
}
public class DataDaoTest {
@Mock
private DataDao<Data> daoMock;
public static List<Data> getData() {
// returns a list here
}
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Test
public void testInsert() {
List<Data> data = getData();
daoMock.insert(Data.class, data);
}
}