SOAP测试客户端Web服务类

时间:2013-11-18 02:46:40

标签: java soap web

我为编写者创建了一个持久化类SOAPLoanCalculator,并且在那里有两个方法。我应该有两个类写几个较小的类。

在SOAPLoanCalculatorTest中,我不明白如何为贷款计算器编写测试。我认为我应该使用一些具体的方法。我的结论是,在“stub”之后。我可以选择几个选项。 enter image description here

您能否告诉我如何处理测试类(如何测试贷款计算器?)。您可以给我一些想法,例如如何调用MonthlyPayment方法并接收回复。其余的我应该能够完成这项工作。

 
public class SOAPLoanCalculator {

public double monthlyPayment(double principal, double interest, double period){

    double mPayment = (principal * interest / 1200) / (1 - Math.pow( 1 / ( 1 + interest / 1200), period) );
    return  mPayment;
}

public double totalInterestPayments(double principal, double interest, double period) {

    double periodicInterest = interest / period;
    double interestPayment = periodicInterest * -principal * Math.pow((1 + periodicInterest), period) / (1 - Math.pow((1 + periodicInterest), period));
    double totalInterestPayment = (interestPayment * period) - principal;   
    return totalInterestPayment;
}

}

import ndnu.wc.SOAPLoanCalculator; import ndnu.wc.SOAPLoanCalculatorStub;

public class SOAPLoanCalculatorTest {

public static void main(String[] args) { SOAPLoanCalculatorStub stub = new SOAPLoanCalculatorStub(); stub. }
public double monthlyPayment(double principal, double interest, double period){ double mPayment = (principal * interest / 1200) / (1 - Math.pow( 1 / ( 1 + interest / 1200), period) ); return mPayment; } public double totalInterestPayments(double principal, double interest, double period) { double periodicInterest = interest / period; double interestPayment = periodicInterest * -principal * Math.pow((1 + periodicInterest), period) / (1 - Math.pow((1 + periodicInterest), period)); double totalInterestPayment = (interestPayment * period) - principal; return totalInterestPayment; }

public static void main(String[] args) { SOAPLoanCalculatorStub stub = new SOAPLoanCalculatorStub(); stub. }

1 个答案:

答案 0 :(得分:1)

您应该使用标准测试框架(如JUnit)来测试您的Web服务。您可以参考http://www.drdobbs.com/web-development/unit-testing-web-services/211201695以了解如何创建测试用例。

如果您想为JUnit使用一些测试工具,可以考虑使用SoapUI。以下是http://www.soapui.org/Test-Automation/integrating-with-junit.html

的示例