NutzCN Logo
问答 nutz中集成testng时无法使用@runwith注解(得不到ioc容器),怎么解决?
发布于 2632天前 作者 qq_a3d32b9c 2624 次浏览 复制 上一个帖子 下一个帖子
标签:

请问论坛高手:
我现在用testng测试,无法用junit的@runwith注解来启动ioc容器,请问有什么替代方法?

```
package com.aoyi.rs;

import com.aoyi.rs.account.modules.models.UserLevel;
import com.aoyi.rs.account.modules.models.UserReferrs;
import com.aoyi.rs.account.modules.serivces.AccountLogService;
import com.aoyi.rs.account.modules.serivces.AccountService;
import com.aoyi.rs.account.modules.serivces.UserLevelService;
import com.aoyi.rs.account.modules.serivces.UserReferrsService;
import org.junit.runner.RunWith;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

@RunWith(NutBookIocTestRunner.class)
@IocBean
public class AccountServiceImplTest {
@Inject
private AccountLogService accountLogService;
@Inject
private AccountService accountService;
@Inject
private UserReferrsService userReferrsService;
@Inject
private UserLevelService userLevelService;

private UserReferrs userRandomOne;
private List<UserLevel> userLevelList;



@Test()

//消费测试 包含分润动作
public void consumeTest(){
int n = 0;
for (int i = 0; i <70 ; i++) {
UserReferrs randomOne = getRandomOne();
Random accural = new Random();
Boolean result = accountService.consume(randomOne.getUser_id(), accural.nextInt(8600));
if (result){
n++;
}
}
System.out.println(n);

5 回复

@RunWith(MyNutTestRunner.class)
@IocBean // 必须有
public class SimpleTest extends Assert {}

****我用的是testng来测试,不能用@Runwith注解呀

类似的思路

做个testng扩展试试?

junit的扩展就挺简单的,但我没用过testng,不知道testng怎么搞

添加回复
请先登陆
回到顶部