【发布时间】:2015-07-23 12:39:10
【问题描述】:
我有一个类似这样的豆子:
@Service
public class A {
@Autowired
private B b;
@PostConstruct
public void setup() {
b.call(param);
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { Application.class, Config.class })
@WebIntegrationTest(randomPort = true)
public class Test {
@Autowired
B b;
@Before
public void setUp() throws Exception {
when(b.call(any())).thenReturn("smth");
}
@Test
public void test() throws Exception {
// test...
}
}
问题是在运行测试时PostConstruct 在setUp 之前被调用。
【问题讨论】:
-
@hzpz A 类有其他逻辑,后者在测试中调用。并回答您的问题,我想测试 A 类的逻辑。
标签: spring junit postconstruct