junit4

Auto download pdf files in Firefox

血红的双手。 提交于 2019-12-05 07:28:27
问题 I'm doing tests with Selenium and JUnit. I'm trying to export a report (pdf and xls). With Selenium, I click the download link, and do a verifcar to assert that the file is in the correct folder. I was able to test with the xls, but Firefox always asks what I want to do with the PDF. The configuration of Firefox, Selenium is this: String downloadPath = new File("src/test/resources/firefox_download").getAbsolutePath(); firefoxProfile.setPreference("browser.download.dir", downloadPath);

Maven, Jenkins - how to build project to different test environments?

筅森魡賤 提交于 2019-12-05 05:15:38
I have a Java project containing junit tests that needs to be run on different test environments (Dev, Staging, etc.) via Jenkins. How can I setup the building of the project to the different environments and how to pass the url, username and the password to maven? Can I use maven 3 profiles to read the environment url, username and password from a property file? Edit: I've added the profiles to the Project POM: <profiles> <profile> <id>Integration</id> </profile> <profile> <id>Staging</id> </profile> <profile> <id>PP1</id> </profile> <profile> <id>PP2</id> </profile> <profile> <id>PP3</id> <

Mock File, FileReader and BufferedReader class using Mockito

a 夏天 提交于 2019-12-05 04:54:37
I got below code in a method which I want to test File f = map.get("key1") BuffereReader r = new BufferedReader(new FileReader(f)); String line=null; do { line=r.readLine(); } while(r!=null); I want to mock this operation so that I can pass the content of the file from the JUnit test case. I have done below: Map fles = Mockito.mock(ConcurrentHashMap.class); File file = Mockito.mock(File.class); Mockito.when(files.get("key1")).thenReturn(file); FileReader fileReader = Mockito.mock(FileReader.class); BufferedReader bufferedReader = Mockito.mock(BufferedReader.class); try { PowerMockito.whenNew

Resources$NotFoundException when calling Robolectric.buildActivity()

孤人 提交于 2019-12-05 03:25:10
I am using Robolectric 3.0 RC3 for unit testing in Android Studio. And I am getting a ResourceNotFoundException every time I run the test. Please help me resolve the issue. build.gradle dependencies { testCompile 'junit:junit:4.12' compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.0.0' testCompile 'org.mockito:mockito-core:1.9.5' testCompile 'org.robolectric:robolectric:3.0-rc3' compile 'com.ibm.icu:icu4j:53.1' } Test Class @Before public void setUp() throws Exception { activity = Robolectric.buildActivity(MainActivity.class).create().get(); } @Test

initializationError with Eclipse and JUNIT4 when executing a single test

て烟熏妆下的殇ゞ 提交于 2019-12-05 03:13:21
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.contactlab.api.test.AbstractTest#setUp() */ @Override @Before public void setUp() throws Exception { super

Testing multiple interface implementations with same tests - JUnit4

我与影子孤独终老i 提交于 2019-12-05 02:33:43
I want to run the same JUnit tests for different interface implementations. I found a nice solution with the @Parameter option: public class InterfaceTest{ MyInterface interface; public InterfaceTest(MyInterface interface) { this.interface = interface; } @Parameters public static Collection<Object[]> getParameters() { return Arrays.asList(new Object[][] { { new GoodInterfaceImpl() }, { new AnotherInterfaceImpl() } }); } } This test would be run twice, first with the GoodInterfaceImpl then with the AnotherInterfaceImpl class. But the problem is I need for most of the testcases a new object. A

Cause of an unexpected behaviour using JUnit 4's expected exception mechanism?

情到浓时终转凉″ 提交于 2019-12-05 02:12:46
I am trying to test that a particular method throws an expected exception from a method. As per JUnit4 documentation and this answer I wrote the test as: @Test(expected=CannotUndoException.class) public void testUndoThrowsCannotUndoException() { // code to initialise 'command' command.undo(); } However, this code fails the JUnit test, reporting the thrown (and expected) exception as an error. The method I'm testing has only this in the body: public void undo() { throw new CannotUndoException(); } Furthermore, the following test passes: public void testUndoThrowsCannotUndoException() { // code

Spring Boot integration tests doesn't read properties files

岁酱吖の 提交于 2019-12-05 01:57:45
问题 I would like to create integration test in which Spring Boot will read a value from .properties file using @Value annotation. But every time I'm running test my assertion fails because Spring is unable to read the value: org.junit.ComparisonFailure: Expected :works! Actual :${test} My test: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {WebTests.ConfigurationClass.class, WebTests.ClassToTest.class}) public class WebTests { @Configuration @ActiveProfiles("test")

How to force a fresh version of the Spring context BEFORE the test executes

家住魔仙堡 提交于 2019-12-04 22:39:51
I use the SpringJUnit4ClassRunner for writing integration tests. I also use @DirtiesContext for tests that leave the context in an broken state behind and that works just fine. But now I have a test the sets an important SystemProperty in an static initializer, which in turn is used in the Spring context. This again works fine when the test executes on its own. But when I run the test with other tests the Spring context gets already created with out that property set and gets reused by my new Test. How can I force the fresh creation of a Spring context in my test, which then will use the

Surefire is not picking up Junit 4 tests

南笙酒味 提交于 2019-12-04 21:00:51
I cannot get Maven Surefire to execute my JUnit 4 tests even after I tried all the advices from another post. My POM: <project> <modelVersion>4.0.0</modelVersion> <groupId>maven-test</groupId> <artifactId>maven-test</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.junit</groupId> <artifactId>com.springsource.org.junit</artifactId> <version>4.4.0</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source