我想模拟一个外部库(Poseidon)
下面的是我要测试的课程。但我不想打电话给Poseidon :: Producer.new
void yourDataGridView_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
if (e.Column.Name == "Id" && e.CellValue1 != null && e.CellValue2 != null)
{
var x = (int)e.CellValue1;
var y = (int)e.CellValue2;
e.SortResult = x == y ? 0 : x == 0 ? 1 : y == 0 ? -1 : x.CompareTo(y);
e.Handled = true;
}
}
我的考试
class KafkaSender < DefaultSender
def initialize(client)
hosts = ["#{client}-kafka.pro.hupi.loc:9092"]
@producer = Poseidon::Producer.new(hosts, "catchbox_api")
end
def send(message)
@producer.send_messages([Poseidon::MessageToSend.new(message.topic, message.to_json)])
end
end
答案 0 :(得分:0)
您可以将模拟直接放在主类上,如下所示:
expect(Poseidon::Producer).to receive(:new).with(["test-kafka.pro.hupi.loc:9092"], "catchbox_api")