この記事の研究では、主にSpring+Junit4インターフェイステストの関連例が含まれています。特定の実装コードは次のとおりです。
<Dependency> groupId> org.springframework </groupid> <artifactid> spring-context </artifactid> <version> 4.3.2.release </version> </dependency> <dependency> <groupid> org.springframework </groupid> <artifactid> spring> spring </artifactid> <Dependency> GroupId> junit </groupId> <Artifactid> junit </artifactid> <バージョン> 4.12 </version> </dependency>
TestInterfaceは、手動で構成するか、自動的にスキャンすることができます
手動構成
Spring構成ファイル構成:
<bean id = "testinterface"> </bean>
自動スキャン
インターフェイス実装クラスの構成
@component public class testinterfaceimplを実装するinterface {スプリング構成ファイルの構成
<コンテキスト:annotation-config/> <context:component-scanベースパッケージ= "com.xxx.servlet"> </context:component-scan>
Import org.junit.test; Import org.junit.runner.runwith; org.springframework.test.context.contextconfigurationをインポートします。 Import org.springframework.test.context.junit4.springjunit4classrunner; javax.annotation.resourceをインポートします。 @runwith(springjunit4classrunner.class)@contextconfiguration(locations = "classpath:applicationcontext.xml")public class test {@resource testinterface testinterface; @test public void test1(){testinterface.test1(1,2); }上記は、Spring+Junit4のインターフェイステスト例のコードに関するこの記事のすべての内容であり、すべての人に役立つことを願っています。興味のある友人は、このサイトの他の関連トピックを引き続き参照できます。欠点がある場合は、それを指摘するためにメッセージを残してください。このサイトへのご支援をありがとうございました!