51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3131|回复: 0
打印 上一主题 下一主题

[原创] 关于jtest测试工具

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2006-8-29 15:46:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
因为我刚用jtest这个测试工具,有个问题想问问大家.
用过jtest人应该知道,这个工具会自动生成junit
用自动生成后的junit进行测试时,会生成空指针异常,
不知道怎么解决这个问题,请教各位啦,谢谢
下面是源代码:import java.util.StringTokenizer;
public class StringUtil {
        /**
     * @pre str != null
     * @throws java.lang.NullPointerException
     */
    public static String[] split(String str,String delim){
               
            String[] result=null;
                StringTokenizer st=null;
                if (str!=null&&delim!=null||str!=""&&delim!=""){
                 st=new StringTokenizer(str,delim);}
       
                int length=st.countTokens();


               
            result= new String[length];
           for (int i=0;i<length;i++){
                   result=st.nextToken();
           }
           return result;
            }
下面是自动生成的junit:
import jtest.JT;

/**
* StringUtilTest is a unit test class for class StringUtil.
* @see StringUtil
* @author Parasoft Jtest 7.5
*/
public class StringUtilTest extends PackageTestCase {

        /**
         * Constructs a test case for the test specified by the name argument.
         * @param name the name of the test case
         * @author Parasoft Jtest 7.5
         */
        public StringUtilTest(String name) {
                super(name);
                /*
                 * This constructor should not be modified.  Any initialization code
                 * should be placed in the setUp() method instead.
                 */
        }

        /**
         * Test for method: static split(java.lang.String,java.lang.String)
         * @throws Throwable Tests may throw any Throwable
         * @see StringUtil#split(java.lang.String,java.lang.String)
         * @author Parasoft Jtest 7.5
         */
        public void testSplit1() throws Throwable {
                // jtest_tested_method
                String[] RETVAL = StringUtil.split((String) null, (String) null);
                // NullPointerException thrown, originator is arg 1 to <Method StringUtil.split(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;>
                // at java.util.StringTokenizer.<init>
                // at java.util.StringTokenizer.<init>
                // at StringUtil.split(StringUtil.java:4)
                // Verified by seabreeze
        }

        /**
         * Test for method: static split(java.lang.String,java.lang.String)
         * @throws Throwable Tests may throw any Throwable
         * @see StringUtil#split(java.lang.String,java.lang.String)
         * @author Parasoft Jtest 7.5
         */
        public void testSplit2() throws Throwable {
                Throwable x0 = null;
                try {

                        // jtest_tested_method
                        String[] RETVAL = StringUtil.split("", (String) null);
                        assertNotNull(RETVAL); // Verified by seabreeze
                        assertEquals(0, RETVAL.length); // Verified by seabreeze
                        // No exception thrown
                        // Verified by seabreeze

                } catch (ThreadDeath td) {
                        throw td;
                } catch (Throwable x1) {
                        x0 = x1;
                }
                JT.assertException(x0, "java.lang.NullPointerException");

        }

        /**
         * Test for method: static split(java.lang.String,java.lang.String)
         * @throws Throwable Tests may throw any Throwable
         * @see StringUtil#split(java.lang.String,java.lang.String)
         * @author Parasoft Jtest 7.5
         */
        public void testSplit3() throws Throwable {
                // jtest_tested_method
                String[] RETVAL = StringUtil.split("0", "");
                assertNotNull(RETVAL); // Verified by seabreeze
                assertEquals(1, RETVAL.length); // Verified by seabreeze
                assertEquals("0", RETVAL[0]); // Verified by seabreeze
                // No exception thrown
                // jtest_unverified
        }

        /**
         * Test for method: static split(java.lang.String,java.lang.String)
         * @throws Throwable Tests may throw any Throwable
         * @see StringUtil#split(java.lang.String,java.lang.String)
         * @author Parasoft Jtest 7.5
         */
        public void testSplit4() throws Throwable {
                // jtest_tested_method
                String[] RETVAL = StringUtil.split("0", (String) null);
                // NullPointerException thrown
                // at java.util.StringTokenizer.skipDelimiters(StringTokenizer.java:186)
                // at java.util.StringTokenizer.countTokens(StringTokenizer.java:332)
                // at StringUtil.split(StringUtil.java:14)
                // jtest_unverified
        }

        /**
         * Test for method: static split(java.lang.String,java.lang.String)
         * @throws Throwable Tests may throw any Throwable
         * @see StringUtil#split(java.lang.String,java.lang.String)
         * @author Parasoft Jtest 7.5
         */
        public void testSplit6() throws Throwable {
                // jtest_tested_method
                String[] RETVAL = StringUtil.split("", "");
                assertNotNull(RETVAL); // Verified by seabreeze
                assertEquals(0, RETVAL.length); // Verified by seabreeze
                // No exception thrown
                // jtest_unverified
        }

/**
         * Used to set up the test. This method is called by JUnit before each of
         * the tests are executed.
         * @see junit.framework.TestCase#setUp()
         * @author Parasoft Jtest 7.5
         */
        public void setUp() throws Exception {
                super.setUp();
                /*
                 * Add any necessary initialization code here (e.g., open a socket).
                 * Call Repository.putTemporary() to provide initialized instances of
                 * objects to be used when testing.
                 */
                // jtest.Repository.putTemporary("name", object);
                _stubs_iteration = new jtest.StubIterationCounter();
        }

        /**
         * Used to clean up after the test. This method is called by JUnit after
         * each of the tests have been completed.
         * @see junit.framework.TestCase#tearDown()
         * @author Parasoft Jtest 7.5
         */
        public void tearDown() throws Exception {
                super.tearDown();
                /*
                 * Add any necessary cleanup code here (e.g., close a socket).
                 */
        }

        /**
         * Utility main method.  Runs the test cases defined in this test class.
         *
         * Usage: java StringUtilTest
         * @param args command line arguments are not needed
         * @author Parasoft Jtest 7.5
         */
        public static void main(String[] args) {
                // junit.textui.TestRunner will print the test results to stdout.
                junit.textui.TestRunner.run(suite());
        }

        /**
         * Create a test suite for running the tests in this class.
         * IndependentTestSuite will run each test case in a separate classloader.
         * @return a test suite to run all of the tests in this class
         * @author Parasoft Jtest 7.5
         */
        public static junit.framework.Test suite() {
                return new jtest.IndependentTestSuite(
                // this class
                        StringUtilTest.class,
                        // fully qualified name of the tested class
                        "StringUtil",
                        // timeout for each test in milliseconds
                        60000);
        }

        /**
         * Get the class object of the class which will be tested.
         * @return the class which will be tested
         * @author Parasoft Jtest 7.5
         */
        public Class getTestedClass() {
                return StringUtil.class;
        }

        /**
         * Used to keep track of how many times a stubbed method has been called.
         * @author Parasoft Jtest 7.5
         */
private jtest.StubIterationCounter _stubs_iteration;
}
// JTEST_CURRENT_ID=-1144487551.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /2 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-6-12 08:47 , Processed in 0.082568 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表