1

だからここに私のコードがあります:

package tests;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

class StatementTester extends TestCase { 
    public StatementTester (String name) { 
        super(name); 
    }

    protected void setUp() { 
    } 

    protected void tearDown() {  
    } 

    public void test1() {
        System.out.println("testing");
        assert(true);
    }

    public static Test suite() { 
        TestSuite suite= new TestSuite(); 
        suite.addTest(new StatementTester("test1")); 
        return suite; 
    }

    public static void main (String[] args) { 
        junit.textui.TestRunner.run (suite());
  } 
}

これを実行しようとすると、次のエラー メッセージが表示されます。

.E
Time: 0.001
There was 1 error:
1) test1(tests.StatementTester) at tests.StatementTester.main(StatementTester.java:30)

FAILURES!!!
Tests run: 1,  Failures: 0,  Errors: 1

Martin Fowler の「Refactoring: Improving the design of existing code」の第 4 章にある例に基づいてコードを作成しました (単純化しましたが、基本構造は同じです)。また、Eclipse 3.5.1 を実行し、JUnit 3 ライブラリを使用します (関連性はわかりませんが、とにかく...)

私が間違っていることについて何かヒントを教えてもらえますか?

4

2 に答える 2

7

まず、Eclipse には、テスト クラスでメインを宣言しなくてもテストを実行できる機能があることをお伝えしたいと思います。

これを行う方法を示すチュートリアルを次に示します (JUnit4 を使用): http://www.vogella.de/articles/JUnit/article.html

于 2011-04-12T13:47:20.553 に答える
1

現在エディターにあるファイルで、ALT-- SHIFT、. または、右クリック->実行->JUnitテスト。XT

于 2011-04-12T14:22:04.950 に答える