📄 shoppingcarttestcase.java
字号:
package wls8unleashed.testing;import java.util.Vector;import junit.framework.Assert;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;public class ShoppingCartTestCase extends TestCase{ private ShoppingCart cart; private CartItem item1; private CartItem item2; private CartItem item3; public ShoppingCartTestCase() { } protected void setUp() { cart = new ShoppingCart(); item1 = new CartItem("Video Card", 1, 149.99); item2 = new CartItem("Monitor", 1, 459.99); item3 = new CartItem("Camera", 1, 289.99); } public void testAddItem() { cart.addItem(item1); Vector items = cart.getItems(); CartItem tmpItem = (CartItem)items.get(0); Assert.assertEquals(tmpItem.getName(), item1.getName()); Assert.assertEquals(tmpItem.getQuantity(), item1.getQuantity()); Assert.assertEquals(tmpItem.getUnitPrice(), item1.getUnitPrice(), 0.0); } public void testNumItems() { cart.addItem(item1); cart.addItem(item2); cart.addItem(item3); Assert.assertTrue(cart.getNumItems() == 3); } public void testTotalCost() { cart.addItem(item1); cart.addItem(item2); cart.addItem(item3); Assert.assertEquals(cart.getTotalCost(), 899.97, 0.0); } public void testEmptyCart() { cart.addItem(item1); cart.emptyCart(); Assert.assertTrue(cart.getNumItems() == 0); } public static Test suite() { TestSuite suite = new TestSuite(ShoppingCartTestCase.class); return suite; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -