junit4

JUnit - assertSame

£可爱£侵袭症+ 提交于 2019-11-30 08:05:12
Can someone tell me why assertSame() do fail when I use values > 127? import static org.junit.Assert.*; ... @Test public void StationTest1() { .. assertSame(4, 4); // OK assertSame(10, 10); // OK assertSame(100, 100); // OK assertSame(127, 127); // OK assertSame(128, 128); // raises an junit.framework.AssertionFailedError! assertSame(((int) 128),((int) 128)); // also junit.framework.AssertionFailedError! } I'm using JUnit 4.8.1. Daniel Engmann The reason is the autoboxing of Java. You use the method: public static void assertSame(Object expected, Object actual) It only works with Objects. When

NoSuchMethodError with Hamcrest 1.3 & JUnit 4.11

限于喜欢 提交于 2019-11-30 07:49:56
Another instance of the NoSuchMethodError for the JUnit & Hamcrest combination. Offending code: assertThat(dirReader.document(0).getFields(), hasItem( new FeatureMatcher<IndexableField, String>(equalTo("Patisnummer"), "Field key", "Field key") { @Override protected String featureValueOf(IndexableField actual) { return actual.name(); } } )); Commented lines 152–157 in IndexerTest.java (commit ac72ce ) Causes a NoSuchMethodError (see http://db.tt/qkkkTE78 for complete output): java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V at org

JUnit right way of test expected exceptions

北战南征 提交于 2019-11-30 07:24:39
问题 Hello guys I was wondering if this way of testing my exception is ok, i have this exception i need to throw in the second test annotation, im receiving as result a red evil bar, and a succeed and a failure, as you can guess the failure is my concern, i have a fail(); there but the reason is because i read thats the way to test the exception and now im confused. Also i have to say im willin get the green bar because im expecting the exception, but i dont know if failure is the right way to see

How to get selected option using Selenium WebDriver with Java

送分小仙女□ 提交于 2019-11-30 06:25:15
问题 I want to get the selected label or value of a drop down using Selenium WebDriver and then print it on the console . I am able to select any value from the drop down, but I am not able to retrieve the selected value and print it: Select select = new Select(driver.findElement(By.id("MyDropDown"))).selectByVisibleText(data[11].substring(1 , data[11].length()-1)); WebElement option = select.getFirstSelectedOption(); But all my efforts were in vain. How do I get the selected option? 回答1: You

Migrating Junit4 tests to androidx: What causes 'delegate runner could not be loaded'?

二次信任 提交于 2019-11-30 04:16:33
I am migrating my app to androidx, I can't seem to get my unit tests working. I took example from Google's AndroidJunitRunnerSample , which has been updated to use the new androidx api. I get the following error when trying to run my tests: java.lang.Exception: Delegate runner 'androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner' for AndroidJUnit4 could not be loaded. Check your build configuration. Here is my module build.gradle: android { defaultConfig { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } } dependencies { // Test dependencies

injecting mock beans into spring context for testing

三世轮回 提交于 2019-11-30 04:00:54
I know similar questions have been asked, e.g. here , but having done a search, I've come upon a solution I'm much happier with here My only problem however, is that I'm not sure how to implement this solution. What I want to be able to do is via the HotswappableTargetSource override the bean definitions of select beans in my application context with my test versions and then run the test. Then for each test case I'd like to specify which beans I want to be hot swappable and then each test must be able to create its own mock versions and swap those in, and be able to swap back again. I am able

Android: Robolectric does not support API level 1

♀尐吖头ヾ 提交于 2019-11-30 03:43:58
This is my basic test class: @RunWith(RobolectricTestRunner.class) public class MainActivityTest { @Before public void setup() { //do whatever is necessary before every test } @Test public void testActivityFound() { Activity activity = Robolectric.buildActivity(MainActivity.class).create().get(); Assert.assertNotNull(activity); } } When I execute my test under Android Studio, with the Terminal window, I have this error: java.lang.UnsupportedOperationException: Robolectric does not support API level 1, sorry! at org.robolectric.SdkConfig.<init>(SdkConfig.java:24) at org.robolectric

What's the best way to set up a per-test or per-class timeout when using <junit> in perBatch forkmode?

我怕爱的太早我们不能终老 提交于 2019-11-30 02:41:43
问题 I want to fail the build if anyone writes a test that takes longer than 1 second to run, but if I run in perTest mode it takes much, much longer. I could probably write a custom task that parses the junit reports and fails the build based on that, but I was wondering if anyone knows or can think of a better option. 回答1: Reviving an old question since the answer doesn't provide an example. You can specify timeout Per test method: @Test(timeout = 100) // Exception: test timed out after 100

How can I get @BeforeClass and @AfterClass equivalent in Junit3?

耗尽温柔 提交于 2019-11-30 02:40:47
问题 I want to back up my application's database before replacing it with the test fixture. I'm forced to use Junit3 because of Android limitations, and I want to implement the equivalent behavior of @BeforeClass an @AfterClass. UPDATE: There is now a tool (Junit4Android) to get support for Junit4 on Android. It's a bit of a kludge but should work. To achieve the @BeforeClass equivalent, I had been using a static variable and initializing it during the first run like this, but I need to be able to

Testing for custom plugin portlet: BeanLocatorException and Transaction roll-back for services testing

廉价感情. 提交于 2019-11-30 02:21:08
My Problems: I can test successfully for CRUD services operation. I was doing an insert on @Before [setUp()] and delete of same data on @After [tearDown()] but going forward I would need to support Transactions rather than writing code for insert and delete. I am successful in fetching single records of my entity but when I fire a search query or try to fetch more than one of my entities I get: com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set for servlet context MyCustom-portlet I have followed some of the following links to set-up Junit with Liferay: Liferay