Pass command line arguments to JUnit test case being run programmatically

You can use java system properties to achieve this. Simply pass what you need with -Dconnectionstring=foobar in the junit command line, or use the java api for system properties to set this programmatically, with System.setProperty(String name, String value), and System.getProperty(String name). In your tests, you can use the @Before or @BeforeClass to set up common … Read more

How to execute JUnit and TestNG tests in same project using maven-surefire-plugin?

Official way with selecting providers. You can also specify multiple providers as dependencies, and they will all be run and produce a common report. This may be especially handy with external providers, since there are few use-cases for combining the included providers. <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <dependencies> <dependency> <groupId>org.apache.maven.surefire</groupId> <artifactId>surefire-junit47</artifactId> <version>2.18.1</version> </dependency> <dependency> <groupId>org.apache.maven.surefire</groupId> <artifactId>surefire-testng</artifactId> <version>2.18.1</version> … Read more

Why Can’t I access src/test/resources in Junit test run with Maven?

Access MainConfig.xml directly. The src/test/resources directory contents are placed in the root of your CLASSPATH. More precisely: contents of src/test/resources are copied into target/test-classes, so if you have the following project structure: . └── src └── test ├── java │   └── foo │   └── C.java └── resources ├── a.xml └── foo └── b.xml It will … Read more

Failed to load ApplicationContext for JUnit test of Spring controller

As mentioned in the discussion: WEB-INF is not really part of the class path. If you use a common template, such as maven, use src/main/resources or src/test/resources to place the app-context.xml in. Then you can use classpath:. Place your config file in src/main/resources/app-context.xml and use the following code: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = “classpath:app-context.xml”) public class PersonControllerTest … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)