junit4

Need help to write a unit test using Mockito and JUnit4

淺唱寂寞╮ 提交于 2019-12-08 23:36:01
问题 Need help to write a unit test for the below code using Mockito and JUnit4, public class MyFragmentPresenterImpl { public Boolean isValid(String value) { return !(TextUtils.isEmpty(value)); } } I tried below method: MyFragmentPresenter mMyFragmentPresenter @Before public void setup(){ mMyFragmentPresenter=new MyFragmentPresenterImpl(); } @Test public void testEmptyValue() throws Exception { String value=null; assertFalse(mMyFragmentPresenter.isValid(value)); } but it returns following

injecting mock beans into spring context for testing

落花浮王杯 提交于 2019-12-08 23:10:19
问题 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

Spring boot integration test fails with Neo4j

懵懂的女人 提交于 2019-12-08 19:54:30
I am new to spring boot. I use Spring Boot 1.5.1 GA and Neo4j starter of spring boot. I tried to create my very first integration test to whether I can insert a new object into the graph database. Here is my test class: package hu.bookandwalk; import static org.junit.Assert.assertEquals; import java.time.LocalDateTime; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.neo4j.ogm.testutil.TestServer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest

akquinet (Android with test archetype) - unit tests are not executed

荒凉一梦 提交于 2019-12-08 19:38:07
问题 I've generated an Android project using the akquinet archetype: mvn archetype:generate \ -DarchetypeArtifactId=android-with-test \ -DarchetypeGroupId=de.akquinet.android.archetypes \ -DarchetypeVersion=1.0.11 \ -DgroupId=com.foo.bar \ -DartifactId=my-android-project \ -Dpackage=com.foo.bar.android This archetype creates a parent project, myproject project with the actual Android application and myproject-it with the integration tests. When I add the following test class into the myproject-it

How should I use EasyMock's @Mock annotation (new in version 3.2)?

独自空忆成欢 提交于 2019-12-08 17:49:24
It looks like EasyMock version 3.2 now supports using annotations to setup mock objects. I am new to EasyMock (and Java in general) and am trying to understand how to use this. Do these annotations do something new or just provide an alternative way to do things? The documentation says: Since EasyMock 3.2, it is now possible to create mocks using annotations. This is a nice and shorter way to create your mocks and inject them to the tested class. Here is the example above, now using annotations: ... Then there is a listing that shows use of the @TestSubject and @Mock annotations, but I don't

IllegalStateException: No Scope registered for scope 'session' on unit test

◇◆丶佛笑我妖孽 提交于 2019-12-08 16:57:00
问题 I have a modified version of the mkyong MVC tutorial. I've added a business layer class Counter . public class Counter { private int i; public int count() { return (this.i++); } //getters and setters and constructors } In mvc-dispatcher-servlet.xml: <bean id="counter" class="com.mkyong.common.Counter" scope="session"> <property name="i" value="0"></property> </bean> This works fine. I now want to create a unit test for this class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration()

How do I make the manifest available during a Maven/Surefire unittest run “mvn test”?

故事扮演 提交于 2019-12-08 16:03:26
问题 How do I make the manifest available during a Maven/Surefire unittest run "mvn test" ? I have an open-source project that I am converting from Ant to Maven, including its unit tests. Here's the project source repository with the Maven project: http://github.com/znerd/logdoc My question pertains to the primary module, called "base". This module has a unit test that tests the behaviour of the static method getVersion() in the class org.znerd.logdoc.Library . This method returns: Library.class

Missing “Run as JUnit Test”

不羁的心 提交于 2019-12-08 14:54:30
问题 I created a JUnit 4 test in Eclipse by right-clicking on a Java class and selecting New JUnit Test Case. When I right-click the test class I get "Run on Server", but not "Run as JUnit Test". I am using Eclipse 3.6.1. 回答1: In my case, Eclipse must have reached a corrupt state. Restarting Eclipse fixed the problem. 回答2: I think I see the problem. You need to have an actual test in the file before Eclipse identifies it as a test case. Try inserting the following: @Test public void foo() { } 回答3:

Use @ClassRule in Kotlin

早过忘川 提交于 2019-12-08 14:35:48
问题 In JUnit you can use @ClassRule to annotate an static field. How can I do this in Kotlin? I tried: object companion { @ClassRule @JvmStatic val managedMongoDb = ... } and object companion { @ClassRule @JvmField val managedMongoDb = ... } but none of the last works because rule isn't executed. I double checked that exactly same rule works fine without static context: @Rule @JvmField val managedMongoDb = ... 回答1: You are not using companion objects correctly. You are declaring an object (single

JUnit4, Spring, Hibernate test context(s) setup

最后都变了- 提交于 2019-12-08 13:27:16
问题 Just looking for a bit of advice really on how to setup "unit" testing with JUnit4 on a Spring 3.0.2 & Hibernate 3.2.7 web app. We currently have just over 500 tests spread across 75+ classes. Our test classes are setup (annotated) similar to the class below: @RunWith(SpringJUnit4ClassRunner.class) @TransactionConfiguration @Transactional @ContextConfiguration(locations={"/location/of/SomeServiceTest-context.xml"}, inheritLocations=false) public class SomeServiceTest extends