跟贴有分 --->>>> up

解决方案 »

  1.   

    import junit.framework.*;public class HelloTest extends TestCase{
        public void testGetHello(){
            Hello aHello = new Hello();        String strExpected = "hello";
            assertEquals(aHello.getHello(),strExpected);
        }
    }
      

  2.   

    你可以用jbuilder自动生成一个,file-->new-->test
      

  3.   

    public class HelloTest extends TestCase{
        public void testGetHello(){
            Hello aHello = new Hello();        String strExpected = "hello";
            assertEquals(aHello.getHello(),strExpected);
        }
    }up
      

  4.   

    不好意思,类没写好,下面是我在JAVA中自动生成的返回一个字符串"hello"的类,现就对这个类进行测试,
    package test_program;//被测试类
    public class get_hello {  public get_hello() {
        return "hello";
      }
    }
    请问我要被测试的类是否一定要加在TestCase()这个里面才能测试,好象在一个包中也不可以
      

  5.   

    "HelloTest.java": Error #: 307 : constructor TestCase() is not public in class junit.framework.TestCase; cannot be accessed from outside package at line 6, column 8大家帮我看看这个错误,问题出在什么地方
      

  6.   

    跟贴有分 --->>>> up
      

  7.   

    "HelloTest.java": Error #: 307 : constructor TestCase() is not public in class junit.framework.TestCase; cannot be accessed from outside package at line 6, column 8if a class'constructor is not public,then the class can't be extended or provide the static factory method.
    so you must be modify the source code of junit.
      

  8.   

    我搞定了,这里是一个测试例子,大家可以调一下,谢谢各位,现在大伙开心一下吧,散分啦!对了,各位,圣诞快乐!JBUILD 6
    1 NEW-->PROJECT
    2 NEW-->CLASS(被测试的类)
    3 NEW-->TEST-->TESTCASE
    //被测试类
    package project_testcar; public class Car {  public int getWheels(){
        return 4;
      }
    }
    //测试类import junit.framework.*;
    public class TestCar extends TestCase {
      protected int expectedWheels;
      protected Car myCar;  public TestCar(String s) {
        super(s);
      }  protected void setUp() {
        expectedWheels = 3;
        myCar = new Car();
      }
      public static Test suite() {
        return  new TestSuite(TestCar.class);
      }
      public void testGetWheels() {
        assertEquals(expectedWheels, myCar.getWheels());
      }
      protected void tearDown() {
      }}