junit

JUnit assertEquals Changes String

烂漫一生 提交于 2019-12-22 05:17:23
问题 I have a JUnit test that is as follows: @Test public void testToDatabaseString() { DateConvertor convertor = new DateConvertor(); Date date = convertor.convert("20/07/1984:00:00:00:00"); String convertedDate = convertor.toDatabaseString(date); assertEquals("to_date('20/07/1984:00:00:00:00', 'DD/MM/YYYY HH24:MI:SS')",convertedDate); } The test fails stating: org.junit.ComparisonFailure: expected:<to_date('20/07/1984[00:]00:00:00', 'DD/MM/YY...> but was:<to_date('20/07/1984[ ]00:00:00', 'DD/MM

How do I get the current DOM with Selenium Java 2.8?

随声附和 提交于 2019-12-22 05:00:37
问题 I'm using the latest version of Selenium and the chromedriver to test a ZK application. During the test, I'd like to dump the DOM (or part of it) to help me find the elements I need (and probably help people who have to maintain the test). The method WebDriver.getPageSource() looked promising but it only returns the HTML as it was sent by the server, not the result after running all the JavaScript code. The JavaScript code is run; I can find elements by ID that I can't see in the output of

Private class unit tests

左心房为你撑大大i 提交于 2019-12-22 04:51:11
问题 How to unit test private (means with package visibility) classed in java? I have a package, only one class is public in this package, other classes are private. How to cover other classed with unit tests? I would like to include unit tests in resting jar. 回答1: Create the unit test class in the same package. For example, If com.example.MyPrivateClass located in src/main/java/com/example/MyPrivateClass.java Then the test class will be in same package com.example.MyPrivateClassTestCase and will

Spring Boot integration test responding with empty body - MockMvc

▼魔方 西西 提交于 2019-12-22 04:44:10
问题 I've seen similar questions to this, but I've yet to find a solution that works for me, so i'm posting it with hopefully enough details to resolve.. So I have the following class: @RunWith(SpringRunner.class) @SpringBootTest public class TestController { @Mock private Controller controller; private MockMvc mockMvc; @InjectMocks private SearchService service; @Before public void setUp(){ MockitoAnnotations.initMocks(this); this.mockMvc = MockMvcBuilders.standaloneSetup(controller)

RunWith(PowerMockRunner.class) does not work with package annotation

自古美人都是妖i 提交于 2019-12-22 04:38:18
问题 I am trying to have RunWith(PowerMockRunner.class) working with my existing package annotation. Versions: powermock 1.4.12 mockito 1.9.0 junit 4.8.2 package-info.java // this is for the package annotation @TestAnnotation(version="1.0") package com.smin.dummy; TestAnnotation.java // this is the the metadata annotation class for package "com.smin.dummy" package com.smin.dummy; import java.lang.annotation.*; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PACKAGE) public @interface

JUnit continue to assert things after expected exception

你。 提交于 2019-12-22 04:18:35
问题 I have something like @Test(expected = IllegalArgumentException.class) public void cdIntoNonExistantFolder() { cdTool.changeDirectory("nonexistant"); assertThat(cdTool.getStatusCode(), not(equalTo(0))); } I believe the assertThat does not run as changeDirectory will throw the exception. Is it possible to make it still run? 回答1: You could use a finally : @Test(expected = IllegalArgumentException.class) public void cdIntoNonExistantFolder() { try { cdTool.changeDirectory("nonexistant"); }

Changing private methods to protected for testing

喜你入骨 提交于 2019-12-22 04:12:27
问题 Is it a good idea to change the private methods to protected for JUNIT testing.? 回答1: It's sometimes useful, yes. If the class is extendable, make sure to make the method final. Also, document the fact that the method is not supposed to be called by subclasses or external classes of the same package. I use the Guava @VisibleForTesting annotation to make it clear that the method should in fact be private. 回答2: No in general not. The idea of unit testing is to test ... units. Or in other words

Run JUnit4-Tests parallel in Eclipse

杀马特。学长 韩版系。学妹 提交于 2019-12-22 03:50:33
问题 maven-surefire-plugin enables running JUnit tests in parallel[1] - is there way to run JUnit-Tests in Eclipse in parallel, too? [1] e.g. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12</version> <configuration> <parallel>methods</parallel> </configuration> </plugin> "Running tests in parallel" https://maven.apache.org/plugins/maven-surefire-plugin/examples/junit.html 回答1: You can use tempus-fugit to run tests in parallel in

Android Studio Unit Testing: unable to find instrumentation OR class not found ex

情到浓时终转凉″ 提交于 2019-12-22 03:42:17
问题 I have a test suite within my Android studio that has the following dir structure: -MainProject -src --com --tests --java.xx.xxx.xx.test Within my AndroidManifest, I have the following: <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="tests.java.xxx.xxx.xxx.test" /> When I run my tests from the command line using: ./gradlew connectedInstrumentTest , I simply get: Tests on Nexus 5 - 4.4.2 failed: Instrumentation run failed due to 'java.lang

Eclipse: bind some key for all unit tests

…衆ロ難τιáo~ 提交于 2019-12-22 02:01:54
问题 I practice TDD and run my tests very often. Eclipse has a nice command to run the last-launched configuration. But when I invoke the command in some unit test class, Eclipse runs only the tests for current unit test class. I want run all my unit tests instead. Yes, I can use the mouse to invoke the command that runs all JUnit tests, but, to repeat: I run tests very often. 回答1: You need to change eclipse's run mode. By default, it will try to run whatever is selected or being edited. You want