junit
Log messages to JUnit console
You should select the test in the tree on the left to see its output in the console on the right:
Method equivalent for @InjectMocks
There is no public API in Mockito for mock injection. Plus as this annotation is mostly driven on the way things are laid out in a test, it is fairly related to the initialization phase of the test. Though it might change at some point in the future. However Mockito annotated fields can be initialized … Read more
IntelliJ – How to jump to source instead of compiled classes from failed unit tests in the “Run” view
You should be able to go to the External Libraries in your Project view (File > Project Structure), find the jar that contains the .class file, and right click (or F4). You will see Open Library Settings. From that dialog, you can attach a src folder to the library.
Why @Rule annotated fields in JUnit has to be public?
The JUnit runner will need to access the field reflectively to run the rule. If the field was private the access would throw IllegalAccessException. Another option would have been to have the runner modify the access from private to public before running the rule. However that could cause problems in case a security manager is … Read more
Failed to connect to binary FirefoxBinary with Selenium in Maven
When I encounter this error it’s usually one of two things. The Selenium version does not support the browser version Double check the Selenium/browser versions are the same when ran from Eclipse vs Maven. Double check Eclipse and Maven are configured to use the same Selenium version. This occurred for me when my browser auto … Read more
JUnit java.lang.NoSuchMethodError: junit.framework.ComparisonFailure.getExpected()Ljava/lang/String
The getExpected() method on junit.framework.ComparisonFailure was only added in JUnit 3.8.2 (remember, junit.framework package is from JUnit 3.8, whereas JUnit 4 uses org.junit). The method wasn’t there in 3.8.1, which is the most common version of 3.x still out there. I think the method was added for easier migration to JUnit 4 tooling, and occasionally … Read more
How to test DAO methods using Mockito?
Here is a good start using Mockito to test your UserDAO. This code uses a good amount of the Mockito features, so you can see how to use them. Let me know if you have questions. import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javax.sql.DataSource; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import … Read more
Run all tests in Junit 4
Though it does not really solve your immediate problem, I find it a very useful general practice to create suites and suites of suites, e.g. for a package something like PackageFooSuite etc. and assemble these suites in one or more suites again, like ModuleFooSuite and have one top-level suite, like AllTestsSuite. That way it’s easy … Read more