main方法的测试

首先main方法测试的主要原理参见下面的链接

http://www.cnblogs.com/ITEagle/archive/2010/07/10/1774888.html


1、callMainFailure

    

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
/**
* <p>
* Tests the main method. <code>System.exit</code> is expected.
* </p>
*
*
@param args
* the arguments.
*/
private static void callMainFailure(String[] args) {
try {
PriceConversionUtility.main(args);

fail(
" System.exit is expected. " );
}
catch (SecurityException e) {
// Good
}
}
不论main方法正常结束还是异常结束都要System.exit因此这个函数在准确性测试和异常测试中都可以用的到

2、MockSecurityManager

    一个测试的帮助类

   

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
import java.security.Permission;

public final class MockSecurityManager extends SecurityManager {
/**
* <p>
* This method throws exception for testing if the status is 1 or 0.
* </p>
*
*
@param status
* The exit status code.
*
*
@throws SecurityException
* Always.
*/
public void checkExit( int status) {
super .checkExit(status);
if (status == 1 || status == 0 || status == - 1 ) {
throw new SecurityException( " Halt for testing. " );
}
}

/**
* <p>
* This method does nothing.
* </p>
*
*
@param perm
* Ignored.
*/
public void checkPermission(Permission perm) {
}
}

 

转载于:https://www.cnblogs.com/ITEagle/archive/2010/07/16/1779206.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值