Reputation: 531
I want to execute a test from a main-class. I have tried:
public static void main(String[] args) {
JUnitCore runner = new JUnitCore();
runner.run(TestClass.class);
}
and
public static void main(String[] args) {
JUnitCore.main(TestClass.class.getName());
}
However, this test is using the Spring-framework and the beans aren't loaded. My test-class looks like this:
@NoDataSet
@ContextConfiguration(locations = { "/.../xxx-beans.xml", "/.../yyy-beans.xml",
"..." }, inheritLocations = false)
@RunWith(SpringJUnit4ClassRunner.class)
public class TestClass extends AbstractTransactionalJUnit4SpringContextTests {
@BeforeClass
public static void beforeClass() {
// some config
}
@Test
public void testSomething() {
// testsomething
}
}
I am using a lot of beans and therefore I can't load the beans manually.
Is there another way to start this test?
Upvotes: 2
Views: 923
Reputation: 136082
try
new JUnitCore().run(new SpringJUnit4ClassRunner(Test1.class));
or simply add
@RunWith(SpringJUnit4ClassRunner.class) to TestClass
Upvotes: 3
Reputation: 531
I found the problem. Apparently, my working directory was set to an incorrect location.
I now use it wit the following main-method:
public static void main(String[] args) {
JUnitCore runner = new JUnitCore();
runner.run(TestClass.class);
}
Upvotes: 0
Reputation: 123960
The class is missing a @RunWith(SpringJUnit4ClassRunner.class)
annotation. Without this annotation, even your build tool or IDE wouldn't be able to execute it correctly.
Upvotes: 0