我想用反射实现Go接口以生成模拟和存根。但是,如果我看一看反射包,我不知道该怎么做(也许是不可能的)。例如:测试是否FUNC电话WriteHeader(404)上ResponseWriter:type ResponseWriterMock struct { // status int //} // How to replacefunc (*ResponseWriterMock) Header() Header {} // this block with func (*ResponseWriterMock) Write([]byte) (i int, e error) {} // a reflectivly func (m *ResponseWriterMock) WriteHeader(status int) { // generated mock? m.status = status // } //responseWriterMock := new(ResponseWriterMock)funcToTest(responseWriterMock)if responseWriterMock.status != 404 { // report error}使用RhinoMocks(C#),我会这样写:var responseWriterMock = MockRepository.GenerateMock<ResponseWriter>();funcToTest(responseWriterMock);responseWriterMock.AssertWasCalled(rw => rw.WriteHeader(404));如何使用反射实现Go接口?
- 2 回答
- 0 关注
- 202 浏览
添加回答
举报
0/150
提交
取消