英文:
How to execute test classes conditionally using Junit 4.11
问题
我有多个测试类,我希望根据一个Bean的值来执行这些测试类。
我的测试类:
@Autowired
protected String abType;
public class abTest extends TestAbstract {
@Test
public void testAddUser() {
---------
--------
--------
}
}
我希望仅在 abType = a 时执行此类或其测试用例;
TestAbstract 类:
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = "classpath:application-context-test.xml")
public abstract class TestAbstract {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
.
.
.
.
.
}
所有的测试类都继承了这个类,我想根据在 config.properties 文件中配置的 beanValue 有条件地运行所有的测试类。
我阅读了多篇相关的帖子,但并没有得到我真正需要的内容。
非常感谢任何提供帮助的人!
英文:
I have multiple test classes and I want to execute test classes based on a bean value.
My test class:
@autowired
protected String abType;
public class abTest extends TestAbstract {
@Test
public void testAddUser() {
---------
--------
--------
}
I want this class or its test cases to execute only when abType = a;
TestAbstract class :
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = "classpath:application-context-test.xml")
public abstract class TestAbstract {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
.
.
.
.
.
}
This class is extended by all the test classes, I want to run all the test classes conditionally based on the beanValue which is configured in config.properties file.
I read multiple posts related to this, but didn't got what I am actually looking for.
Any help would be really appreciated.!!
答案1
得分: 1
我通常在JUnit4中使用assumeTrue
。也许这对你也是一个选择。
@Test
public void testOnlyWhenConditionTrue() {
assumeTrue(conditionTrue);
... // 你的测试步骤
}
英文:
I usually use the assumeTrue in JUnit4. Maybe this is an option for you.
@Test
public void testOnlyWhenConditionTrue() {
assumeTrue(conditionTrue);
... // your test steps
}
Assumptions and Conditional Test Execution with JUnit 4 and 5
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论