junit

Why assertEquals and assertSame in junit return the same result for two instances same class?

会有一股神秘感。 提交于 2019-12-20 11:36:08
问题 According to documentation assertEquals() Asserts that two objects are equal. assertSame() Asserts that two objects refer to the same object. So I am expecting that if I have a class like below class SomeClass {} then SomeClass someClass1= new SomeClass(); SomeClass someClass2= new SomeClass(); assertSame(someClass1,someClass2); // fail assertEquals(someClass1,someClass2); // fail the assertEquals should pass and assertSame should fail, as the value of both classes are equal but they have

Generating JUnit stubs for new methods in existing class in Eclipse

╄→гoц情女王★ 提交于 2019-12-20 11:20:31
问题 This question is tangentially related to How can I create JUnit stub methods in eclipse? but it doesn't answer my specific question. Assuming you have an existing JUnit test case class, if you add a method to the target class (or choose to test a previously untested method), is there a way to tell Eclipse to generate the stub for the "new" method(s) in the existing TestCase without creating a new test case class? 回答1: Open the package hierarchy panel. Navigate down to the class that you've

JUnit Reports — Test Method Descriptions

爱⌒轻易说出口 提交于 2019-12-20 11:12:20
问题 I am trying to see if there is a way to include "descriptive text" in my junit reports by way of javadocs. JUnit 4 doesnt seem to support the 'description' attribute for the @Test annotation like TestNG does. So far from what I have researched there is only one tool out there called javadoc-junit (http://javadoc-junit.sourceforge.net/). However I could not get this to work since it seems to be incompatible with Junit 4. What I want is some way to provide a sentence or two of text with my each

JUnit Reports — Test Method Descriptions

痴心易碎 提交于 2019-12-20 11:11:13
问题 I am trying to see if there is a way to include "descriptive text" in my junit reports by way of javadocs. JUnit 4 doesnt seem to support the 'description' attribute for the @Test annotation like TestNG does. So far from what I have researched there is only one tool out there called javadoc-junit (http://javadoc-junit.sourceforge.net/). However I could not get this to work since it seems to be incompatible with Junit 4. What I want is some way to provide a sentence or two of text with my each

Trying to run ANT JUnit target in debug mode in Eclipse

巧了我就是萌 提交于 2019-12-20 10:58:23
问题 Here is my ANT JUnit target <target name="test" depends="compile" > <junit failureProperty="test.failure" > <jvmarg value="-Xdebug" /> <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5432" /> <classpath> <pathelement path="${basedir}\..\Core\lib\junit-4.10.jar"/> <pathelement path="${basedir}\..\Suggestion\lib\ssce.jar"/> <pathelement path="C:\Java\javamail-1.4.1\mail.jar"/> <pathelement path="C:\Java\commons-net-2.0\commons-net-ftp-2.0.jar"/> <pathelement path="$

Drawbacks of TestNG compared to jUnit? [closed]

旧时模样 提交于 2019-12-20 10:36:24
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . I'm familiar with jUnit, and heard TestNG might be a solution to some of jUnit's annoyences - e.g. its insistence to create a separate instance of the test class per test, thus forcing me to use static field for objects I want to reuse between tests. (Let's say you agree with

Unit testing in Java - what is it? [closed]

╄→尐↘猪︶ㄣ 提交于 2019-12-20 10:27:03
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . Can you explain in a few sentences: Why we need it / why they make our life easier ? How to unit-test [simple example in Java] ? When do not we need them / types of projects we can leave unit-testing out? useful links 回答1: Why we need it / why they make our life easier ? It allows

@Value “Could not resolve placeholder” in Spring Boot Test

余生长醉 提交于 2019-12-20 10:23:06
问题 I want to take a Junit test for Spring-boot as below: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {ApplicationTest.class}) public class TestOnSpring { @Value("${app.name}") private String appName; @Test public void testValue(){ System.out.println(appName); } } and ApplicationTest.java like this @ComponentScan("org.nerve.jiepu") @EnableAutoConfiguration() public class ApplicationTest { public static void main(String[] args) { SpringApplication.run(ApplicationTest

JUnit assertions : make the assertion between floats

我只是一个虾纸丫 提交于 2019-12-20 10:18:04
问题 I need to compare two values : one a string and the other is float so I convert the string to float then try to call assertEquals(val1,val2) but this is not authorized , I guess that the assertEquals doesn't accept float as arguments. What is the solution for me in this case ? 回答1: You have to provide a delta to the assertion for Floats: Assert.assertEquals(expected, actual, delta) While delta is the maximum difference (delta) between expected and actual for which both numbers are still

Selenium + JUnit: test order/flow?

社会主义新天地 提交于 2019-12-20 09:59:26
问题 I am using Selenium to test my java web app's html pages (JSPs actually). My web app requires a flow to access each pages (it is a small online game web app), as in: to get to page B you'd need to go to page A, enter some text and press a button to get to page B. Obviously I already have some tests to verify that page A is working properly. I would like to be able to write more tests in order to check that after the tests for page A run I'll get my tests for page B running (and so on for the