![](/img/trans.png)
[英](Java)TestNG/Junit -How to Unit test a protected method in a class with no zero-argument-constructor?
[英]How to do a Unit test (Junit 4) to a method that works in a Class that has a Constructor with an unknown object parameter
我需要知道如何解決這個問題
public class SigFX extends SigProduct {
private FX fx;
public SigFX(final ReportRo row) {
super(row);
fx = (FX) getTrade().getProduct();
}
@Override
public Object getStrtDt() {
return getTrade().getTradeDate();
}
@Override
public Object getEndDt() {
return getTrade().getSettleDate();
}
}
我需要為此 class 方法啟動單元測試(JUnit 4),但我真的不知道如何解決我在 testClass 中實例化 SigFX 的方式,因為它有一個 Object 類型 ReportRo 作為參數。
你可以這樣做:
final ReportRo row = new ReportRo(); //I don't know class ReportRo, so it might be possible that you have to add some parameters to constructor.
final SigFX sigFX = new SigFX(row);
//you can access your methods of sigFX as usual and test it as you want
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.