Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lakernote
EasyAdmin
提交
680619ca
E
EasyAdmin
项目概览
lakernote
/
EasyAdmin
9 个月 前同步成功
通知
14
Star
3
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
EasyAdmin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
680619ca
编写于
9月 22, 2022
作者:
lakernote
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
controller层单元测试
上级
ee53c296
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
135 addition
and
0 deletion
+135
-0
src/test/java/com/laker/admin/module/sys/controller/TestingWebApplicationTests.java
...min/module/sys/controller/TestingWebApplicationTests.java
+18
-0
src/test/java/com/laker/admin/module/sys/controller/TestingWebApplicationTests2.java
...in/module/sys/controller/TestingWebApplicationTests2.java
+28
-0
src/test/java/com/laker/admin/module/sys/controller/TestingWebApplicationTests3.java
...in/module/sys/controller/TestingWebApplicationTests3.java
+27
-0
src/test/java/com/laker/admin/module/sys/controller/TestingWebApplicationTests4.java
...in/module/sys/controller/TestingWebApplicationTests4.java
+28
-0
src/test/java/com/laker/admin/module/sys/controller/TestingWebApplicationTests5.java
...in/module/sys/controller/TestingWebApplicationTests5.java
+34
-0
未找到文件。
src/test/java/com/laker/admin/module/sys/controller/TestingWebApplicationTests.java
0 → 100644
浏览文件 @
680619ca
package
com.laker.admin.module.sys.controller
;
import
org.junit.Assert
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
// 告诉 Spring Boot 寻找一个主配置类(例如,一个带有的@SpringBootApplication)并使用它来启动 Spring 应用程序上下文
public
class
TestingWebApplicationTests
{
@Autowired
SysUserController
sysUserController
;
@Test
public
void
contextLoads
()
{
Assert
.
assertNotNull
(
sysUserController
.
getAll
());
}
}
\ No newline at end of file
src/test/java/com/laker/admin/module/sys/controller/TestingWebApplicationTests2.java
0 → 100644
浏览文件 @
680619ca
package
com.laker.admin.module.sys.controller
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.web.servlet.MockMvc
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultHandlers
.
print
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
// 在这个测试中,启动了完整的 Spring 应用程序上下文,但没有服务器。
@SpringBootTest
// 告诉 Spring Boot 寻找一个主配置类(例如,一个带有的@SpringBootApplication)并使用它来启动 Spring 应用程序上下文
@AutoConfigureMockMvc
public
class
TestingWebApplicationTests2
{
@Autowired
private
MockMvc
mockMvc
;
@Test
public
void
shouldReturnDefaultMessage
()
throws
Exception
{
this
.
mockMvc
.
perform
(
get
(
"/"
))
.
andDo
(
print
())
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
().
string
(
""
));
}
}
\ No newline at end of file
src/test/java/com/laker/admin/module/sys/controller/TestingWebApplicationTests3.java
0 → 100644
浏览文件 @
680619ca
package
com.laker.admin.module.sys.controller
;
import
org.junit.Assert
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.web.server.LocalServerPort
;
/**
* 启动一个真实的tomcat容器
* WebEnvironment.DEFINED_PORT:用程序定义的端口
* WebEnvironment.RANDOM_PORT:使用随机端口,配合@LocalServerPort注解使用
*/
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
)
public
class
TestingWebApplicationTests3
{
@Autowired
SysUserController
sysUserController
;
@LocalServerPort
int
port
;
@Test
public
void
contextLoads
()
{
Assert
.
assertNotNull
(
sysUserController
);
System
.
out
.
println
(
"单元测试tomcat端口为:"
+
port
);
}
}
\ No newline at end of file
src/test/java/com/laker/admin/module/sys/controller/TestingWebApplicationTests4.java
0 → 100644
浏览文件 @
680619ca
package
com.laker.admin.module.sys.controller
;
import
org.junit.Assert
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.web.client.TestRestTemplate
;
/**
* 启动一个真实的tomcat容器
* WebEnvironment.DEFINED_PORT:用程序定义的端口
* WebEnvironment.RANDOM_PORT:使用随机端口,配合@LocalServerPort注解使用
*/
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
DEFINED_PORT
)
public
class
TestingWebApplicationTests4
{
@Autowired
SysUserController
sysUserController
;
@Autowired
TestRestTemplate
restTemplate
;
@Test
public
void
contextLoads
()
{
Assert
.
assertNotNull
(
sysUserController
);
Assert
.
assertTrue
(
this
.
restTemplate
.
getForObject
(
"http://localhost:8080"
+
"/"
,
String
.
class
)
!=
null
);
}
}
\ No newline at end of file
src/test/java/com/laker/admin/module/sys/controller/TestingWebApplicationTests5.java
0 → 100644
浏览文件 @
680619ca
package
com.laker.admin.module.sys.controller
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.http.MediaType
;
import
org.springframework.test.web.servlet.MockMvc
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
content
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
/**
* 启动一个真实的tomcat容器
* WebEnvironment.DEFINED_PORT:用程序定义的端口
* WebEnvironment.RANDOM_PORT:使用随机端口,配合@LocalServerPort注解使用
*/
@SpringBootTest
(
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
DEFINED_PORT
)
@AutoConfigureMockMvc
public
class
TestingWebApplicationTests5
{
@Autowired
private
MockMvc
mvc
;
@Test
public
void
contextLoads
()
throws
Exception
{
mvc
.
perform
(
get
(
"/"
)
.
contentType
(
MediaType
.
APPLICATION_JSON
))
.
andExpect
(
status
().
isOk
())
.
andExpect
(
content
()
.
contentTypeCompatibleWith
(
MediaType
.
APPLICATION_JSON
));
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录