springboot单元测试类

2023-11-01  本文已影响0人  南瓜pump
单元测试的pom依赖
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
在test包下面创建单元测试类:
单元测试类
测试代码
import com.pump.demopro.DemoProApplication;
import com.pump.demopro.rabbitmqtest.producer.Sender;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;

/**
 * @ProjectName: demo-pro
 * @Package: com.pump.rabbitmqtest
 * @ClassName: RabbitTests
 * @Author: pump
 * @Description:
 * @Date: 2023-11-02 9:30:50
 * @Version: 1.0
 */
@ActiveProfiles("dev")
@RunWith(value= SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoProApplication.class)
public class RabbitTests {

    @Autowired
    private Sender sender;

    @Test
    public void sendTest() throws Exception {
        while(true){
            String msg = new Date().toString();
            sender.send(msg);
            Thread.sleep(1000);
        }
    }

}
上一篇下一篇

猜你喜欢

热点阅读