好象是,在junit中的System.out.println("something"),看不到自己的输出;
我觉得是不是已经控制了System.out流.

解决方案 »

  1.   

    下面是所有测试类
    public class AllTests { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest( ItemTest.suite() );
    suite.addTest( AuditTest.suite() );
    suite.addTest( CategoryItemTest.suite() ); return suite;
    } public static void main(String args[]) {
    TestRunner.run( suite() );
    }下面是我要测试的那个类:
    public void testItemData() throws Exception {
    System.out.println("111111111111111");
    initData(); ItemDAO itemDAO = new ItemDAO(); Item a1 = itemDAO.getItemById(auctionOne.getId(), false);
    assertEquals(a1.getInitialPrice(),
                 new MonetaryAmount(new BigDecimal("1.99"), Currency.getInstance(Locale.US))); HibernateUtil.commitTransaction();
    HibernateUtil.closeSession();
    System.out.println("2222222222222222222");
    assertEquals(true,false);
    } // ********************************************************** // public void testPlaceBid() throws Exception {
    System.out.println("3333333333333333");
    initData(); // TODO: Test doesn't consider currency properly! ItemDAO itemDAO = new ItemDAO();
    UserDAO userDAO = new UserDAO(); Bid currentMaxBid = itemDAO.getMaxBid(auctionTwo.getId());
    Bid currentMinBid = itemDAO.getMinBid(auctionTwo.getId());
    Item a2 = itemDAO.getItemById(auctionTwo.getId(), true); // Fail, auction is not active yet
    try {
    BigDecimal bidAmount = new BigDecimal("99.99");
    MonetaryAmount newAmount = new MonetaryAmount(bidAmount, Currency.getInstance("USD"));
    a2.placeBid(userDAO.getUserById(u3.getId(), false),
    newAmount,
    currentMaxBid,
    currentMinBid);
    } catch (BusinessException success) {} // Fail, user isn't an admin
    try {
    a2.approve(u3);
    } catch (PermissionException success) {} // Success, set active
    a2.setPendingForApproval();
    a2.approve(u1); // Success, place a bid
    try {
    BigDecimal bidAmount = new BigDecimal("100.00");
    MonetaryAmount newAmount = new MonetaryAmount(bidAmount, Currency.getInstance("USD"));
    a2.placeBid(userDAO.getUserById(u3.getId(), false),
    newAmount,
    currentMaxBid,
    currentMinBid); } catch (BusinessException failure) {
    throw failure;
    } // Fail, bid amount is too low
    try {
    BigDecimal bidAmount = new BigDecimal("99.99");
    MonetaryAmount newAmount = new MonetaryAmount(bidAmount, Currency.getInstance("USD"));
    a2.placeBid(userDAO.getUserById(u3.getId(), false),
    newAmount,
    currentMaxBid,
    currentMinBid);
    } catch (BusinessException success) {} // TODO: Implement test for auction dates... HibernateUtil.commitTransaction();
    HibernateUtil.closeSession();
    System.out.println("4444444444444444444");
    } // ********************************************************** // public ItemTest(String x) {
    super(x);
    System.out.println("000000000");
    }输出是:
    000000000000
    但是
    11111111111111
    2222222222222222222
    3333333333333
    444444444
    都没有输出
    开始我以为测试方法没运行,所以我在
    System.out.println("2222222222222222222");
    assertEquals(true,false);
    那里添加了一个让测试失败的语句,测试结果表明运行到了这里,所以不明白为什么222222222这样的地方为什么没在控制台输出。