zoukankan      html  css  js  c++  java
  • spring整合测试

    一、pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>org.example</groupId>
        <artifactId>A02spring</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <dependencies>
            <!--https://mvnrepository.com/artifact/org.springframework/spring-context-->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>5.2.8.RELEASE</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>5.2.8.RELEASE</version>
                <scope>test</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/junit/junit -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.13</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>

    二、测试类

    /*
    @ContextConfiguration:指定spring配置
        属性:
            classes:指定配置类
            locations:指定配置文件,要加关键字classpath:
    */
    @RunWith(SpringJUnit4ClassRunner.class)//替换junit的main方法,使用spring提供的方法
    @ContextConfiguration(classes = SpringConfig.class)
    public class MySpringTest {
        @Autowired
        private Grade grade;
    
        @Test
        public void test01() {
            grade.studentMethod();
        }
    }
  • 相关阅读:
    poj 3264(RMQ或者线段树)
    LCA上的RMQ模板算法
    LCA离线算法Tarjan的模板
    poj 1330(初探LCA)
    hdu 3367(与最大生成树无关。无关。无关。重要的事情说三遍+kruskal变形)
    hdu 4496(并查集逆向添边)
    hdu 1829(继续扩展并查集)
    poj 1182 (扩展并查集)
    hdu 3038(扩展并查集)
    hdu 3371(kruskal)
  • 原文地址:https://www.cnblogs.com/linding/p/13665470.html
Copyright © 2011-2022 走看看