簡體   English   中英

如何對在具有未知 object 參數的構造函數的 Class 中工作的方法進行單元測試(Junit 4)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM