eclipse 创建maven web项目_idea创建maven项目

1,创建项目之前先打开Settings--->Build--->Build Tools,在右侧的VM OPtions:右侧的输入框中添加 -DarchetypeCatalog=internal 运行参数 (不做上面操作的话会导致maven 骨架生成速度缓慢到令人发指,卡在running tmp archetypexxxtmp这一步)

5c112ede9475116574c3501c773a7f77.png

2,创建maven web项目,new Project,选择Maven,然后选中Create from archetype,等待加载,加载完成后,选中webapp项目,按照下图顺序点击后点击下一步

97fdcf6b923d6e95ac6fa3e87c916755.png

然后如图所示:

a021633d8c5d87620b239265ee2421a2.png

然后点击下一步,到了maven和maven的setting配置的页面,

ea73a0b27d59a87147211f8c0c384c8a.png

然后打开Project Structure,在下图的main文件夹上点击右键new floder,然后创建test,test下的com.xxx.xxx,然后设置为Test,或者Test Resources类型的包

99b6e18ada0b89c9e543cd7be13c4ab3.png

创建测试用例:

@SpringBootApplication
@EnableEurekaServer
public class DemoEurekaApplication {
 
	public static void main(String[] args) {
		SpringApplication.run(DemoEurekaApplication.class, args);
	}
}

也可如下:

import java.util.Calendar;
import java.util.Date;

/**
 * Created by asus1 on 2018/6/11.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes={ProductServerApplication.class,ProductTest.class})
public class ProductTest {
    @Autowired
    private ProductService p;

    @Test
    public void testProdecutAdd() {
        ProductDtoRequest productDtoRequest = new ProductDtoRequest();
        ProductDto pdto = new ProductDto();
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        for (int i = 0; i < 20; i++) {
            c.add(Calendar.DAY_OF_MONTH,1);
            pdto.setTradingtTimeEnd(c.getTime());
            pdto.setProductName("测试产品"+System.currentTimeMillis());
            productDtoRequest.setProductDto(pdto);
            try {
                Boolean aBoolean = p.addProduct(productDtoRequest);
                System.out.println(aBoolean);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

测试用例:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by asus1 on 2018/6/11.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes={ProductServerApplication.class,ProductTest.class})
public class ProductTest {
    @Autowired
    private ProductService p;

    @Test
    public void testProdecutAdd() {
        ProductDtoRequest productDtoRequest = new ProductDtoRequest();
        ProductDto pdto = new ProductDto();
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        for (int i = 0; i < 20; i++) {
            c.add(Calendar.DAY_OF_MONTH,1);
            pdto.setTradingtTimeEnd(c.getTime());
            pdto.setProductName("测试产品"+System.currentTimeMillis());
            productDtoRequest.setProductDto(pdto);
            try {
                Boolean aBoolean = p.addProduct(productDtoRequest);
                System.out.println(aBoolean);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 

也可以如下:

新建单元测试的启动类

@SpringBootApplication
public class Run {
    public static void main(String[] args) {
        SpringApplication.run(Run.class, args);
    }
}

新建测试类

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Run.class)
@EnableAutoConfiguration
@EnableAliOss
public class RunTests {
 
    @Autowired
    private OssService ossService;
 
    @Test
    public void test() throws Exception {
        ossService.getToken("aa.sb3");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值