junit4

In Eclipse, how do I see the input to Assert.assertEquals when it fails?

痴心易碎 提交于 2019-12-05 18:34:08
I'm not much of an Eclipse guru, so please forgive my clumsiness. In Eclipse, when I call Assert.assertEquals(obj1,obj2) and that fails, how do I get the IDE to show me obj1 and obj2? I'm using JExample , but I guess that shouldn't make a difference. Edit : Here's what I see: (source: yfrog.com ) . If the information in the JUnit view is not enough for you, you can always set a exception breakpoint on, for example, java.lang.AssertionError. When running the test, the debugger will stop immediately before the exception is actually being thrown. Comparison with failure trace is not a easy task

How do I pass parameters to a Junit test from Ant?

筅森魡賤 提交于 2019-12-05 18:13:28
问题 I'm using Junit under Ant to perform Selenium Test.My test cases need to read files which contain test data(in order to accomplish data driven test). I don't mind embedding the file names in the test cases, but I'd like to have the name of the directory where the data files are stored parameterized in the build.xml file. What's the best way to pass information like that from build.xml down into the test cases? Is it a good idea to use ant property? Is it possible to inject Junit4 parameter

How to test whether a method has been overriden in junit?

眉间皱痕 提交于 2019-12-05 17:58:01
I have this question, is there a test annotation or assertion which can tell if a method has been overriden in junit? I'm currently implementing a test case which should tell whether the class Foo 's method toString() has overriden its super class. Thanks. you could do it like this probably: class.getMethod("toString").getDeclaringClass(); Here is a sample: class Test { public String toString(){ return "From test"; } } public static void main(String[] args) throws NoSuchMethodException, SecurityException { String resut = Test.class.getMethod("toString").getDeclaringClass().getName(); System

Is it possible to automatically open Google Chrome devtools?

大城市里の小女人 提交于 2019-12-05 14:45:37
问题 Given that Selenium 2 closes the devtools window which contains my emulator profile saved under my user profile for chrome. Is there a way to trigger devtools to open using a selenium script? Here is the info on the devtools window closing issue https://sites.google.com/a/chromium.org/chromedriver/help/devtools-window-keeps-closing I feel a little exhausted trying some of these Chromium override parameters only one of which seems to work http://peter.sh/experiments/chromium-command-line

Selenium web driver not able to close firefox instance if a Test cases is failed

和自甴很熟 提交于 2019-12-05 14:16:52
i folks, i am using junit with selenium web driver 2.28. the problem is if i run a successful test case the web drives is able to close the firefox instance, but when a test case fails the selenium web driver is not able to close the firefox. i am using FF 15.0.1 with selenium-server-standalone-2.28.0.jar. please respond thanks Sahil private void startWebdriver() throws UIException{ //2) Prevent re-use. if(UIHandlerWD.this.profile == null) throw new UIException( UIException.Code.UI, "Webdriver instance cannot be instantiated." ); //3) Configure Selenium Webdriver. if (this.profile.browserType

Loop through array, each element a JUnit test

这一生的挚爱 提交于 2019-12-05 13:51:16
问题 I have a JUnit 4 test that loops through an array of test data: public @Test void testAll() { final Object[][] sets = new Object[][] { // SET TYPE VALUE // --- valid sets // groups x(s(A,1, B,1, C,1), G), x(s(A,4, B,4, D,4), G), x(s(A,8, B,8, D,8, C,8), G), x(s(J,J, B,4, D,4), G, 4*3), x(s(A,9, J,J, D,9), G, 9*3), x(s(A,2, B,2, C,2), G), x(s(A,4, B,4, J,J), G, 4*3), x(s(A,4, B,4, C,4, D,4), G), // runs x(s(A,1, A,2, A,3), R), x(s(B,8, B,9, B,10), R), x(s(J,J, C,2, C,3), R, 6), x(s(D,8, D,9, J

Spring JUnit4 manual-/auto-wiring dilemma

此生再无相见时 提交于 2019-12-05 11:41:12
I ran into an issue that can only be explained with my fundamental lack of understanding of Spring's IoC container facilities and context setup, so I would ask for clarification regarding this. Just for reference, an application I am maintaing has the following stack of technologies: Java 1.6 Spring 2.5.6 RichFaces 3.3.1-GA UI Spring framework is used for bean management with Spring JDBC module used for DAO support Maven is used as build manager JUnit 4.4 is now introduced as test engine I am retroactively (sic!) writing JUnit tests for the application and what suprised me is that I wasn't

How can I test exception in completable future?

删除回忆录丶 提交于 2019-12-05 09:42:20
I have been converting some code to be asynchronous. The original unit test used the annotation @Test(expected = MyExcpetion.class) but I don't think this will work because the exception I want to assert on is wrapped in java.util.concurrent.ExcutionException . I did try calling my future like this but my assertion is still failing and I don't love that I had to add in return null myApiCall.get(123).exceptionally((ex) -> { assertEquals(ex.getCause(),MyCustomException.class) return null } I also tried this flavor but still not working myApiCall.get(123).exceptionally((ex) -> { assertThat(ex

how to accept input from user in Junit console

冷暖自知 提交于 2019-12-05 09:01:11
I am trying to write Junit test case for the function given below: class A{ int i; void set() { Scanner in=new Scanner(System.in); i=in.nextInt(); } } Now my problem is when i create a Junit test case for it, it does not except input from user: public void testSet() throws FileNotFoundException { System.out.println("set"); A instance = new A(); int i=1; instance.set(i); // TODO review the generated test code and remove the default call to fail. //fail("The test case is a prototype."); } Please suggets what should i do to accept input from user. You can use System.setIn() to mock user input:

Junit4 + Spring 2.5 : Asserts throw “NoClassDefFoundError”

戏子无情 提交于 2019-12-05 07:59:59
I've been coding tests in Junit4 with Spring, and I got this funny behavior: If my tests are passing like this, everything is fine: @Test public void truthTest(){ assertTrue(true); //Ok } But, if my test fails: @Test public void truthTest(){ assertTrue(false); //ERROR } Then instead of a test failure I receive an ugly and cryptic stack trace, This is it: http://pastie.org/429912 Sorry for this ugly dump, but its the only data I've got to explain the problem (I "pastied" it for readability) I'm really puzzled, has anyone encountered this kind of problem before? Thanks in advance! http://jira