【发布时间】:2019-03-20 05:10:12
【问题描述】:
由于某种原因,我的测试类的 setUp() 方法没有在我的测试方法之前被调用。
import static org.junit.jupiter.api.Assertions.*;
import org.junit.After;
import org.junit.Before;
import org.junit.jupiter.api.Test;
class BlockchainAuctionTest {
private BlockchainAuction auction;
@Before
public void setUp() {
auction = new BlockchainAuction();
System.out.println("setUp");
}
@After
public void tearDown() {
System.out.println("tearDown");
}
@Test
void testOneBid() {
Bid bid = new Bid("Bitcoin", "Devon", 1.0);
assertTrue(auction.recordNewBid(bid), "first bid should be added without error");
}
}
具体来说,我在显示
的行上收到了一个空指针异常assertTrue(auction.recordNewBid(bid), "first bid should be added without error");
因为拍卖尚未初始化。我正在使用 Eclipse。
【问题讨论】:
标签: java unit-testing testing junit