การวิจัยในบทความนี้ส่วนใหญ่เกี่ยวข้องกับตัวอย่างที่เกี่ยวข้องของการทดสอบอินเตอร์เฟส Spring+Junit4 รหัสการใช้งานเฉพาะมีดังนี้
<การพึ่งพา> <roupId> org.springframework </groupId> <ratifactid> สปริงเท็กซ์ </artifactid> <version> 4.3.2.release </version> </การพึ่งพา> <การพึ่งพา> <loupid> org.springframework </groupid> <Ederency> <roupId> Junit </GroupId> <ratifactId> Junit </artifactId> <version> 4.12 </Sent> </derness>
TestInterface สามารถกำหนดค่าได้ด้วยตนเองหรือสแกนโดยอัตโนมัติ
การกำหนดค่าด้วยตนเอง
การกำหนดค่าไฟล์การกำหนดค่าสปริง:
<bean id = "testinterface"> </ebean>
การสแกนอัตโนมัติ
การกำหนดค่าในคลาสการใช้งานอินเตอร์เฟส
@Component คลาสสาธารณะ TestInterfaceimpl ใช้ testinterface {การกำหนดค่าไฟล์การกำหนดค่าสปริง
<บริบท: Annotation-config/> <บริบท: Component-Scan base-base-package = "com.xxx.servlet"> </บริบท: Component-Scan>
นำเข้า org.junit.test; นำเข้า org.junit.runner.runwith; นำเข้า org.springframework.test.context.contextconfiguration; นำเข้า org.springframework.test.context.junit4.springjunit4classrunner; นำเข้า Javax.annotation.Resource; @runwith (springjunit4classrunner.class) @contextconfiguration (locations = "classpath: applicationcontext.xml") การทดสอบคลาสสาธารณะ {@resource testinterface testinterface; @Test โมฆะสาธารณะ test1 () {testInterface.test1 (1,2); -ข้างต้นเป็นเนื้อหาทั้งหมดของบทความนี้เกี่ยวกับรหัสสำหรับตัวอย่างการทดสอบอินเตอร์เฟสของ Spring+Junit4 และฉันหวังว่ามันจะเป็นประโยชน์กับทุกคน เพื่อนที่สนใจสามารถอ้างถึงหัวข้ออื่น ๆ ที่เกี่ยวข้องในเว็บไซต์นี้ต่อไป หากมีข้อบกพร่องใด ๆ โปรดฝากข้อความไว้เพื่อชี้ให้เห็น ขอบคุณเพื่อนที่ให้การสนับสนุนเว็บไซต์นี้!