junit4

initializationError with Eclipse and JUNIT4 when executing a single test

空扰寡人 提交于 2020-01-02 02:51:07
问题 My test class is this one: /** * The Class TestAddSubscriber. */ @RunWith(LabelledParameterized.class) public class TestAddSubscriber extends AbstractTestSubscriber { /** * Instantiates a new test add subscriber. * * @param label * the label * @param apiKey * the api key * @param userKey * the user key * @param customerId * the customer id */ public TestAddSubscriber(String label, String apiKey, String userKey, int customerId) { super(label, apiKey, userKey, customerId); } /** * @see com

Running Unit Tests using Maven in Spring LTW Environment

自作多情 提交于 2020-01-01 09:10:33
问题 I am developing an application in a ddd architecture using Spring LoadTimeWeaving feature. The problem is i can run my Junit tests using eclipse but not through Maven. I have tried all the options given on various sites but it simply isn't working. I get the following exception: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [sun

Use different Spring test context configuration for different test methods

♀尐吖头ヾ 提交于 2020-01-01 02:34:07
问题 We have a Spring based JUnit test class which is utilizing an inner test context configuration class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = ServiceTest.Config.class) public class ServiceTest { @Test public void someTest() { ... @Configuration @PropertySource(value = { "classpath:application.properties" }) @ComponentScan({ "..." }) public static class Config { ... New functionalities have been recently introduced to the Service class, for which the concerned

Run all tests in Junit 4

与世无争的帅哥 提交于 2019-12-31 10:03:13
问题 I want to be able to run all tests in a project programmatically. I know Eclipse has a "Run as JUnit test" configuration which somehow grabs all the tests in a project and run them. Is there any way for me to also grab the list of tests programmatically and run them? Or is there some good way to construct a test suite containing all the test cases without manually listing out every one (all 700+) of them? I've tried the "New... -> Test Suite" option in Eclipse, but that seems to work only for

Junit 4.12 Issue testing exception

被刻印的时光 ゝ 提交于 2019-12-31 05:18:06
问题 I have a simple method trying to fetch some file. I would like to test when the file is none existent and this is where my problem begins. The test keeps failing. The method is something like : public Configuration populateConfigs(Configuration config) throws UnRetriableException { try { .... } catch (IOException | ConfigurationException e) { log.error(" getConfiguration : ", e); throw new UnRetriableException(e); } throw new UnRetriableException("problem getting config files."); } In my

How to print current executing JUnit test method while running all tests in a class or suite using ANT?

眉间皱痕 提交于 2019-12-31 02:28:07
问题 I have a set of JUnit Test Cases and I execute them from ANT using the junit task. While executing the tests, in the console I get to see only which test case (i.e. Java class) is currently running, but not the test method. Is there a way I can print the current executing test method? Or is there any other way to do this other than having my own JUnit test runner? Sample Console Output [junit] Running examples.TestCase1 [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 2.835 sec

Junit: splitting integration test and Unit tests

孤人 提交于 2019-12-29 10:03:45
问题 I've inherited a load of Junit test, but these tests (apart from most not working) are a mixture of actual unit test and integration tests (requiring external systems, db etc). So I'm trying to think of a way to actually separate them out, so that I can run the unit test nice and quickly and the integration tests after that. The options are.. Split them into separate directories. Move to Junit4 (from v3) and annotate the classes to separate them. Use a file naming convention to tell what a

JUnit 4.11 get test result in @After

﹥>﹥吖頭↗ 提交于 2019-12-29 07:41:38
问题 Is there any way I can get the test result in the teardown ( @After ) method? I'd like to do clean up after the tests depending on the result. Could not find much details about @After in the junit docs. 回答1: The closest thing to what you're asking for would probably be the TestWatcher rule. That won't give you access to a returned result or anything, but you can use it (or create your own TestRule and combined with the Description object, you could annotate your methods differently to

Easy way to get a test file into JUnit

心已入冬 提交于 2019-12-29 03:12:31
问题 Can somebody suggest an easy way to get a reference to a file as a String/InputStream/File/etc type object in a junit test class? Obviously I could paste the file (xml in this case) in as a giant String or read it in as a file but is there a shortcut specific to Junit like this? public class MyTestClass{ @Resource(path="something.xml") File myTestFile; @Test public void toSomeTest(){ ... } } 回答1: You can try @Rule annotation. Here is the example from the docs: public static class

Can Selenium take a screenshot on test failure with JUnit?

江枫思渺然 提交于 2019-12-28 06:18:20
问题 When my test case fails, especially on our build server, I want to take a picture / screenshot of the screen to help me debug what happened later on. I know how to take a screenshot, but I was hoping for a way in JUnit to call my takeScreenshot() method if a test fails, before the browser is closed. No, I don't want to go edit our bazillions of tests to add a try/catch. I could maybe, just possibly be talked into an annotation, I suppose. All of my tests have a common parent class, but I can