测试类添加两个注解
@RunWith(SpringJUnit4ClassRunner.class)和@ContextConfiguration(locations = "classpath:applicationContext.xml")
如下: @RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = "classpath:applicationContext.xml")public class ShoppingServiceImplTest { @Resource private ShoppingService service; @Test public void addGoodsToCart() throws Exception { UserShoppingCart cart=new UserShoppingCart(); cart.setCartId(UUID.randomUUID().toString()); cart.setUserUserId("f3544efc-5c12-470e-b22e-80kfh30bbec1"); cart.setProductId("1"); cart.setShopId(1); cart.setProductNum(2); int status=service.addGoodsToCart(cart); assertTrue(status==1); } }
时间: 2024-10-14 13:01:16