Let's say you want to test your DonkeyController:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.test.util.ReflectionTestUtils; | |
public class DonkeyControllerTest { | |
DonkeyController donkeyController; | |
DonkeyDAO donkeyDAO; | |
@Before | |
public void setUp() throws Exception { | |
donkeyController = new DonkeyController(); | |
donkeyDAO = new DonkeyDAO(); | |
ReflectionTestUtils.setField(donkeyController, "donkeyDAO", donkeyDAO); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.test.util.ReflectionTestUtils; | |
public class DonkeyControllerTest { | |
DonkeyController donkeyController; | |
DonkeyDAO donkeyDAO; | |
@Before | |
public void setUp() throws Exception { | |
donkeyController = new DonkeyController(); | |
donkeyDAO = new DonkeyDAO(); | |
ReflectionTestUtils.setField(donkeyController, "donkeyDAO", donkeyDAO); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-test</artifactId> | |
<version>${spring.version}</version> | |
</dependency> |