h*e
2 楼
import java.io.IOException;
public interface ExchangeRate {
double getRate(String inputCurrency, String outputCurrency) throws
IOException;
}
import java.io.IOException;
public class Currency {
private String units;
private long amount;
private int cents;
public Currency(double amount, String code) {
this.units = code;
setAmount(amount);
}
private void setAmount(double amount) {
this.amount = new Double(amount).longValue();
this.cents = (int) ((amount * 100.0) % 100);
}
public Currency toEuros(ExchangeRate converter) {
if ("EUR".equals(units)) return this;
else {
double input = amount + cents/100.0;
double rate;
try {
rate = converter.getRate(units, "EUR");
double output = input * rate;
return new Currency(output, "EUR");
} catch (IOException ex) {
return null;
}
}
}
public boolean equals(Object o) {
if (o instanceof Currency) {
Currency other = (Currency) o;
return this.units.equals(other.units)
&& this.amount == other.amount
&& this.cents == other.cents;
}
return false;
}
public String toString() {
return amount + "." + Math.abs(cents) + " " + units;
}
}
import junit.framework.TestCase;
import org.easymock.EasyMock;
import java.io.IOException;
public class CurrencyTest extends TestCase {
public void testToEuros() throws IOException {
Currency testObject = new Currency(2.50, "USD");
Currency expected = new Currency(3.75, "EUR");
ExchangeRate mock = EasyMock.createMock(ExchangeRate.class);
EasyMock.expect(mock.getRate("USD", "EUR")).andReturn(1.5);
EasyMock.replay(mock);
Currency actual = testObject.toEuros(mock);
assertEquals(expected, actual);
}
}
不管真正的ExchangeRate concrete class在不在, 有没有bug,
上面的Junit根本就没有测试真正的class/method, 其文档说验证方法的调用种类、次
数、顺序,可以令 Mock 对象返回指定的值或抛出指定异常。这我看到了, 但这种测
试到底价值何在?
public interface ExchangeRate {
double getRate(String inputCurrency, String outputCurrency) throws
IOException;
}
import java.io.IOException;
public class Currency {
private String units;
private long amount;
private int cents;
public Currency(double amount, String code) {
this.units = code;
setAmount(amount);
}
private void setAmount(double amount) {
this.amount = new Double(amount).longValue();
this.cents = (int) ((amount * 100.0) % 100);
}
public Currency toEuros(ExchangeRate converter) {
if ("EUR".equals(units)) return this;
else {
double input = amount + cents/100.0;
double rate;
try {
rate = converter.getRate(units, "EUR");
double output = input * rate;
return new Currency(output, "EUR");
} catch (IOException ex) {
return null;
}
}
}
public boolean equals(Object o) {
if (o instanceof Currency) {
Currency other = (Currency) o;
return this.units.equals(other.units)
&& this.amount == other.amount
&& this.cents == other.cents;
}
return false;
}
public String toString() {
return amount + "." + Math.abs(cents) + " " + units;
}
}
import junit.framework.TestCase;
import org.easymock.EasyMock;
import java.io.IOException;
public class CurrencyTest extends TestCase {
public void testToEuros() throws IOException {
Currency testObject = new Currency(2.50, "USD");
Currency expected = new Currency(3.75, "EUR");
ExchangeRate mock = EasyMock.createMock(ExchangeRate.class);
EasyMock.expect(mock.getRate("USD", "EUR")).andReturn(1.5);
EasyMock.replay(mock);
Currency actual = testObject.toEuros(mock);
assertEquals(expected, actual);
}
}
不管真正的ExchangeRate concrete class在不在, 有没有bug,
上面的Junit根本就没有测试真正的class/method, 其文档说验证方法的调用种类、次
数、顺序,可以令 Mock 对象返回指定的值或抛出指定异常。这我看到了, 但这种测
试到底价值何在?
o*g
3 楼
帮我师姐发帖,希望能找到合适的访问学者位置,下面是她的基本信息,可直接联系其
本人,谢谢!
施树云,女,1979年生,博士,中南大学副教授,湖南省青年骨干教师,中南大学升华
育英学者。已于2011年获得国家留学基金委公派留学项目资助,指派国家为美国,可于
2012年任何时间到美国进行研究工作,研究领域可为分析化学,药物分析学,药物临床
药理学等相关方向。
2001年-2004年,中南大学分析化学专业,硕士;
2004年-2007年,浙江大学药物分析学专业,博士,研究内容天然产物活性成分的指纹
图谱研究及活性成分分离和结构鉴定;
2007年-2009年,中南大学临床药理研究所,博士后,研究内容为药物体内代谢物结构
鉴定及药物与生物大分子的作用研究;
2009年迄今,中南大学化学化工学院副教授,研究方向为分析化学、天然药物化学和临
床药理学。主持了国家自然科学基金(21005089),中央高校基本科研业务费(
201012200015),湖南省自然科学基金(10JJ4006),湖南省科技计划(2009RS3030),中
国博士后基金(20080440991),第二批中国博士后科学基金特别资助(200902478)等多个
省部级项目,同时参与了国家863计划,国家自然科学基金,国家科技重大专项,湖南
省重大专项等项目。在Trend. Anal. Chem., J. Chromatogr. A, J. Inorg. Chem.,
Food Chem., J. Chromatogr. B等学术刊物上发表论文40余篇,申请专利16项(11项被
授权)。
E-mail: s*******[email protected]
本人,谢谢!
施树云,女,1979年生,博士,中南大学副教授,湖南省青年骨干教师,中南大学升华
育英学者。已于2011年获得国家留学基金委公派留学项目资助,指派国家为美国,可于
2012年任何时间到美国进行研究工作,研究领域可为分析化学,药物分析学,药物临床
药理学等相关方向。
2001年-2004年,中南大学分析化学专业,硕士;
2004年-2007年,浙江大学药物分析学专业,博士,研究内容天然产物活性成分的指纹
图谱研究及活性成分分离和结构鉴定;
2007年-2009年,中南大学临床药理研究所,博士后,研究内容为药物体内代谢物结构
鉴定及药物与生物大分子的作用研究;
2009年迄今,中南大学化学化工学院副教授,研究方向为分析化学、天然药物化学和临
床药理学。主持了国家自然科学基金(21005089),中央高校基本科研业务费(
201012200015),湖南省自然科学基金(10JJ4006),湖南省科技计划(2009RS3030),中
国博士后基金(20080440991),第二批中国博士后科学基金特别资助(200902478)等多个
省部级项目,同时参与了国家863计划,国家自然科学基金,国家科技重大专项,湖南
省重大专项等项目。在Trend. Anal. Chem., J. Chromatogr. A, J. Inorg. Chem.,
Food Chem., J. Chromatogr. B等学术刊物上发表论文40余篇,申请专利16项(11项被
授权)。
E-mail: s*******[email protected]
y*d
4 楼
这个测试的是 Currency 的 toEuros,不是 ExchangeRate
【在 h*********e 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: import java.io.IOException;
: public interface ExchangeRate {
: double getRate(String inputCurrency, String outputCurrency) throws
: IOException;
: }
: import java.io.IOException;
: public class Currency {
: private String units;
: private long amount;
: private int cents;
【在 h*********e 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: import java.io.IOException;
: public interface ExchangeRate {
: double getRate(String inputCurrency, String outputCurrency) throws
: IOException;
: }
: import java.io.IOException;
: public class Currency {
: private String units;
: private long amount;
: private int cents;
o*g
5 楼
帮我师姐发帖,希望能找到合适的访问学者位置,下面是她的基本信息,可直接联系其
本人,谢谢!
施树云,女,1979年生,博士,中南大学副教授,湖南省青年骨干教师,中南大学升华
育英学者。已于2011年获得国家留学基金委公派留学项目资助,指派国家为美国,可于
2012年任何时间到美国进行研究工作,研究领域可为分析化学,药物分析学,药物临床
药理学等相关方向。
2001年-2004年,中南大学分析化学专业,硕士;
2004年-2007年,浙江大学药物分析学专业,博士,研究内容天然产物活性成分的指纹
图谱研究及活性成分分离和结构鉴定;
2007年-2009年,中南大学临床药理研究所,博士后,研究内容为药物体内代谢物结构
鉴定及药物与生物大分子的作用研究;
2009年迄今,中南大学化学化工学院副教授,研究方向为分析化学、天然药物化学和临
床药理学。主持了国家自然科学基金(21005089),中央高校基本科研业务费(
201012200015),湖南省自然科学基金(10JJ4006),湖南省科技计划(2009RS3030),中
国博士后基金(20080440991),第二批中国博士后科学基金特别资助(200902478)等多个
省部级项目,同时参与了国家863计划,国家自然科学基金,国家科技重大专项,湖南
省重大专项等项目。在Trend. Anal. Chem., J. Chromatogr. A, J. Inorg. Chem.,
Food Chem., J. Chromatogr. B等学术刊物上发表论文40余篇,申请专利16项(11项被
授权)。
E-mail: s*******[email protected]
本人,谢谢!
施树云,女,1979年生,博士,中南大学副教授,湖南省青年骨干教师,中南大学升华
育英学者。已于2011年获得国家留学基金委公派留学项目资助,指派国家为美国,可于
2012年任何时间到美国进行研究工作,研究领域可为分析化学,药物分析学,药物临床
药理学等相关方向。
2001年-2004年,中南大学分析化学专业,硕士;
2004年-2007年,浙江大学药物分析学专业,博士,研究内容天然产物活性成分的指纹
图谱研究及活性成分分离和结构鉴定;
2007年-2009年,中南大学临床药理研究所,博士后,研究内容为药物体内代谢物结构
鉴定及药物与生物大分子的作用研究;
2009年迄今,中南大学化学化工学院副教授,研究方向为分析化学、天然药物化学和临
床药理学。主持了国家自然科学基金(21005089),中央高校基本科研业务费(
201012200015),湖南省自然科学基金(10JJ4006),湖南省科技计划(2009RS3030),中
国博士后基金(20080440991),第二批中国博士后科学基金特别资助(200902478)等多个
省部级项目,同时参与了国家863计划,国家自然科学基金,国家科技重大专项,湖南
省重大专项等项目。在Trend. Anal. Chem., J. Chromatogr. A, J. Inorg. Chem.,
Food Chem., J. Chromatogr. B等学术刊物上发表论文40余篇,申请专利16项(11项被
授权)。
E-mail: s*******[email protected]
g*g
6 楼
EasyMock does a few things. It mocks your object easily.
It can check both input and output of your method. And
it can verify the sequence of called methods.
【在 h*********e 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: import java.io.IOException;
: public interface ExchangeRate {
: double getRate(String inputCurrency, String outputCurrency) throws
: IOException;
: }
: import java.io.IOException;
: public class Currency {
: private String units;
: private long amount;
: private int cents;
It can check both input and output of your method. And
it can verify the sequence of called methods.
【在 h*********e 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: import java.io.IOException;
: public interface ExchangeRate {
: double getRate(String inputCurrency, String outputCurrency) throws
: IOException;
: }
: import java.io.IOException;
: public class Currency {
: private String units;
: private long amount;
: private int cents;
m*l
7 楼
干吗不自己锚定目标申请呢?我看她的条件还不错,还能够做点实验,应该还是有想法的.
找个自己学术界的大牛,毛遂自荐,准备一下CV,多半能成功.
强烈建议:对方补钱,对方不出力,等于浪费自己的时间,千万别靠关系应贴上去,不受待
见....
找个自己学术界的大牛,毛遂自荐,准备一下CV,多半能成功.
强烈建议:对方补钱,对方不出力,等于浪费自己的时间,千万别靠关系应贴上去,不受待
见....
p*w
8 楼
mock是把你不要测的东西mock出去,只是让他提供最基本的返回,在这个例子里面,这
个unit test主要是测toEuro里的逻辑,不用测exchangerate是否正确,所以mock了
exchangerate,让他返回一个你可以控制的值,从而让你判断toEuro是否做了应该做的
事情。
【在 h*********e 的大作中提到】![](/moin_static193/solenoid/img/up.png)
: import java.io.IOException;
: public interface ExchangeRate {
: double getRate(String inputCurrency, String outputCurrency) throws
: IOException;
: }
: import java.io.IOException;
: public class Currency {
: private String units;
: private long amount;
: private int cents;
个unit test主要是测toEuro里的逻辑,不用测exchangerate是否正确,所以mock了
exchangerate,让他返回一个你可以控制的值,从而让你判断toEuro是否做了应该做的
事情。
【在 h*********e 的大作中提到】
![](/moin_static193/solenoid/img/up.png)
: import java.io.IOException;
: public interface ExchangeRate {
: double getRate(String inputCurrency, String outputCurrency) throws
: IOException;
: }
: import java.io.IOException;
: public class Currency {
: private String units;
: private long amount;
: private int cents;
相关阅读
Postdoc opportunity多酶共固定在纳米载体上免费送最高$250 Amazon GC 任意消费一笔SPG 信用卡求助专业问题:纳米颗粒表面的有机coating在光下解吸AIChE meeting is great!康奈尔大学生物材料工程有个Tenure-track助理教授职位Amex Gold Premier信用卡送1800刀 Match 125K BonusAmex 开卡送1000刀 Gold Premier Card Match 75K points bonus免费送最高$250 Amazon GC 任意消费一笔SPG 信用卡材料学本人化工硕士一枚,找工作崩溃边缘,求推荐,求指点AICHE合租PhD openings in Materials Science, Engineering, and Commerc (转载)food simulant (转载)有没有人能推荐P&ID标准绘图的参考书Amex 开卡送1000刀 Gold Premier Card Match 75K points bonusDiscover More Card- $150 CashBack Bonus 赶紧申请AICHE 同寻合租转一个上海瑞士香精香料公司的职位给大家Amex 开卡送1000刀 Gold Premier Card Match 75K points bonus