一、宝塔
1.选择宝塔Linux(如果之前使用过服务器,需要重置服务器)
2.放行端口
3.在地址栏访问宝塔面板首页地址
首次登陆需要在根据提示查询账号和密码
4.在菜单栏中选择软件管理下载所需软件
(至少有mysql、tomcat、nginx、Docker管理器)
5.添加站点
6.进入站点的目录,删除默认文件
7.上传打包好的文件(直接文件拉取到目录中)
8.访问公网IP即成功
9.在wwwroot目录中重新创建一个目录,将后端打包的jar包放入
10.添加java项目
(如果tomcat开启,则需要关闭,否则8080端口会被占用)
项目执行命令需要改为
/usr/bin/java -jar -Xmx1024M -Xms256M /www/wwwroot/user-center-backend/user-center-backend-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod
如果显示为运行中就行
然后去服务器面板,在防火墙中放行8080端口
然后访问8080端口(前面要加上我们之前所设置的公网IP,5步骤)
🐶(如果出现报错,可以先直接去宝塔面板中防火墙是否开启8080端口,否则按步骤来)
- 先在终端查看8080端口IPV4是否启动
- 修改本地设置再打包
- 在宝塔面板中放行8080端口
即成功
二、Docker部署
docker 是容器,可以将项目的环境(比如 java、nginx)和项目的代码一起打包成镜像,所有同学都能下载镜像,更容易分发和移植。
再启动项目时,不需要敲一大堆命令,而是直接下载镜像、启动镜像就可以了。
docker 可以理解为软件安装包。
1.先查看Docker是否安装,否则需要安装(官网、宝塔面板)
2.编写后端DockerFile文件
我们如何把前后端项目制作成镜像,对此我们需要一个文件来定义,就我们把前后端项目的依赖、启动流程等,全部写道一个文件里面,文件名就叫Dockerfile(建议到github等平台参考同类项目直接复制粘贴(比如springboot))
Dockerfile编写:
- FROM 依赖的基础镜像
- WORKDIR 工作目录
- COPY 从本机复制文件
- RUN 执行命令
- CMD / ENTRYPOINT(附加额外参数)指定运行容器时默认执行的命令
FROM maven:3.5-jdk-8-alpine as builder # Copy local code to the container image. WORKDIR /app COPY pom.xml . COPY src ./src # Build a release artifact. RUN mvn package -DskipTests # Run the web service on container startup. # 注意第三个参数需要添写自己的jar包 CMD ["java","-jar","/app/target/user-center-backend-0.0.1-SNAPSHOT.jar","--spring.profiles.active=prod"]
3.在Linux中cd 到/www/wwwroot下 用git拉去后端项目
# 利用git命令clone远程仓库的代码 git clone git@github.com:1851823350/user-center.git(ssh地址)
4.根据Dockerfile构建后端镜像
//后端(没权限用sudo) user-center-backend>> sudo docker build -t user-center-backend:v0.0.1 .
5.前端Dockerfile和nginx.conf
创建Dockerfile
FROM nginx WORKDIR /usr/share/nginx/html/ USER root COPY ./docker/nginx.conf /etc/nginx/conf.d/default.conf COPY ./dist /usr/share/nginx/html/ EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
新建docker文件夹,在里面新建nginx.conf
server { listen 80; # gzip config gzip on; gzip_min_length 1k; gzip_comp_level 9; gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml; gzip_vary on; gzip_disable "MSIE [1-6]\."; root /usr/share/nginx/html; include /etc/nginx/mime.types; location / { try_files $uri /index.html; } }
6.git提交代码后,在Linux中cd 到/www/wwwroot项目
# 利用git命令clone远程仓库的代码 git clone git@github.com:1851823350/user-center.git(ssh地址)
7.构建前端Docker项目
user-center-backend>> cd .. wwwroot>> cd user-center-frontend //前端(没有权限用sudo) user-center-frontend>> sudo docker build -t user-center-frontend:v0.0.1 . //可以看下已经安装的镜像(没有权限用sudo) user-center-frontend>> sudo docker images #REPOSITORY TAG IMAGE ID CREATED SIZE #user-center-frontend v0.0.1 b0bfb35288eb 27 seconds ago 144MB #user-center-backend v0.0.1 ec4c8279aed2 49 minutes ago 217MB #nginx latest fa5269854a5e 4 days ago 142MB #maven 3.5-jdk-8-alpine fb4bb0d89941 3 years ago 119MB
这里如果想考虑优化性能可以从减小文件SIZE和减少构建时间(比如多阶段构建,可以丢弃前阶段不需要的内容)
8.启动
# 前端 docker run -p 80:80 -d user-center-frontend:v0.0.1 # 后端 docker run -p 8080:8080 user-center-backend:v0.0.1
变量 | Definition所在节点/边 | Use所在节点/边 | DU-Path | 测试条件 |
subject | 1 | 4 | 1-2-3-4 | TCOUND1 |
sbuject | 1 | <7,9> | 1-2-3-4-5-6-7-9 | TCOUND2 |
sbuject | 1 | <7,10> | 1-2-3-4-5-6-7-10 | TCOUND4 |
sbuject | 1 | <13,14> | 1-2-3-4-5-6-7-9-11-12-13-14 | TCOUND5 |
sbuject | 1 | <13,16> | 1-2-3-4-5-6-7-9-11-12-13-16 | TCOUND6 |
pattern | 1 | 5 | 1-2-3-4-5 | TCOUND7 |
pattern | 1 | <7,9> | 1-2-3-4-5-6-7-9 | TCOUND8 |
pattern | 1 | <7,10> | 1-2-3-4-5-6-7-10 | TCOUND9 |
pattern | 1 | <13,14> | 1-2-3-4-5-6-7-9-11-12-13-14 | TCOUND10 |
pattern | 1 | <13,16> | 1-2-3-4-5-6-7-9-11-12-13-16 | TCOUND11 |
NOTFOUND | 1 | 14 | 1-2-3-4-5-6-7-9-11-12-13-14 | TCOUND12 |
lsub | 2 | 9 | 2-3-4-5-6-7-9 | TCOUND13 |
lsub | 2 | 17 | 2-3-4-5-6-7-9-11-12-13-14-15-17 | TCOUND14 |
lsub | 2 | <7,9> | 2-3-4-5-6-7-9 | TCOUND15 |
lsub | 2 | <7,10> | 2-3-4-5-6-7-10 | TCOUND16 |
lsub | 2 | <13,14> | 2-3-4-5-6-7-9-11-12-13-14 | TCOUND17 |
lsub | 2 | <13,16> | 2-3-4-5-6-7-9-11-12-13-16 | TCOUND18 |
rtnlndex | 2 | 8 | 2-3-4-5-6-8 | TCOUND19 |
rtnlndex | 2 | 14 | 2-3-4-5-6-7-9-11-12-13-14 | TCOUND20 |
rtnlndex | 9 | 14 | 2-3-4-5-6-7-9-11-12-13-14 | TCOUND21 |
lspat | 3 | 15 | 3-4-5-6-7-9-11-12-13-14-15 | TCOUND22 |
subjectLen | 4 | <6,7> | 4-5-6-7 | TCOUND23 |
subjectLen | 4 | <6,8> | 4-5-6-8 | TCOUND24 |
patternLen | 5 | <6,7> | 5-6-7 | TCOUND25 |
patternLen | 5 | <6,8> | 5-6-8 | TCOUND26 |
Ipat | 11 | 16 | 11-12-13-16 | TCOUND27 |
Ipat | 11 | <12,13> | 11-12-13 | TCOUND28 |
Ipat | 11 | <12,17> | 11-12-17 | TCOUND29 |
Ipat | 11 | <13,14> | 11-12-13-14 | TCOUND30 |
Ipat | 11 | <13,16> | 11-12-13-16 | TCOUND31 |
测试覆盖项 | 变量 | Definition所在 节点/边 | Use所在 节点/边 | DU-Path | 覆盖的测 试条件 |
TCOVER1 | subject | 1 | <13,14> | 1-2-3-4-5-6-7-9-11-12-13-14 | TCOUND5 |
TCOVER2 | pattern | 1 | <13,14> | 1-2-3-4-5-6-7-9-11-12-13-14 | TCOUND10 |
TCOVER3 | NOTFOUND | 1 | 14 | 1-2-3-4-5-6-7-9-11-12-13-14 | TCOUND12 |
TCOVER4 | lsub | 2 | 17 | 2-3-4-5-6-7-9-11-12-13-14-15-17 | TCOUND14 |
TCOVER5 | rtnlndex | 2 | 14 | 2-3-4-5-6-7-9-11-12-13-14 | TCOUND20 |
TCOVER6 | rtnlndex | 9 | 14 | 2-3-4-5-6-7-9-11-12-13-14 | TCOUND21 |
TCOVER7 | lspat | 3 | 15 | 3-4-5-6-7-9-11-12-13-14-15 | TCOUND22 |
TCOVER8 | subjectLen | 4 | <6,7> | 4-5-6-7 | TCOUND23 |
TCOVER9 | patternLen | 5 | <6,7> | 5-6-7 | TCOUND25 |
TCOVER10 | Ipat | 11 | <13,16> | 11-12-13-16 | TCOUND31 |
用例编号 | subject[] | pattern[] | 执行路径 | 覆盖的覆盖项 | 预期输出 |
1 | {'a','b','c','d','d'} | {'a','b','c','d'} | 1-2-3--4-5-6-7-9-11-12-13-16-12-17-6-8 | TCOVER1 TCOVER2 TCOVER3 TCOVER4 TCOVER5 TCOVER7 TCOVER8 TCOVER10 | 1 |
2 | {'a','b','c','d','d'} | {'a','b','c','e'} | 1-2-3-4-5-6-7-9-11-12-13-14-15-17-6-8 | TCOVER6 TCOVER9 | -1 |
DU-Paths 测试方法设计测试用例
测试覆盖项
测试覆盖项 | 变量 | Definition所在节点/边 | Use所在节点/边 | DU-Path | 测试条件 |
TCOVER1 | subject | 1 | 4 | 1-2-3-4 | TCOUND1 |
TCOVER2 | sbuject | 1 | <7,9> | 1-2-3-4-5-6-7-9 | TCOUND2 |
TCOVER3 | sbuject | 1 | <7,10> | 1-2-3-4-5-6-7-10 | TCOUND4 |
TCOVER4 | sbuject | 1 | <13,14> | 1-2-3-4-5-6-7-9-11-12-13-14 | TCOUND5 |
TCOVER5 | sbuject | 1 | <13,16> | 1-2-3-4-5-6-7-9-11-12-13-16 | TCOUND6 |
TCOVER6 | pattern | 1 | 5 | 1-2-3-4-5 | TCOUND7 |
TCOVER7 | pattern | 1 | <7,9> | 1-2-3-4-5-6-7-9 | TCOUND8 |
TCOVER8 | pattern | 1 | <7,10> | 1-2-3-4-5-6-7-10 | TCOUND9 |
TCOVER9 | pattern | 1 | <13,14> | 1-2-3-4-5-6-7-9-11-12-13-14 | TCOUND10 |
TCOVER10 | pattern | 1 | <13,16> | 1-2-3-4-5-6-7-9-11-12-13-16 | TCOUND11 |
TCOVER11 | NOTFOUND | 1 | 14 | 1-2-3-4-5-6-7-9-11-12-13-14 | TCOUND12 |
TCOVER12 | lsub | 2 | 9 | 2-3-4-5-6-7-9 | TCOUND13 |
TCOVER13 | lsub | 2 | 17 | 2-3-4-5-6-7-9-11-12-13-14-15-17 | TCOUND14 |
TCOVER14 | lsub | 2 | <7,9> | 2-3-4-5-6-7-9 | TCOUND15 |
TCOVER15 | lsub | 2 | <7,10> | 2-3-4-5-6-7-10 | TCOUND16 |
TCOVER16 | lsub | 2 | <13,14> | 2-3-4-5-6-7-9-11-12-13-14 | TCOUND17 |
TCOVER17 | lsub | 2 | <13,16> | 2-3-4-5-6-7-9-11-12-13-16 | TCOUND18 |
TCOVER18 | rtnlndex | 2 | 8 | 2-3-4-5-6-8 | TCOUND19 |
TCOVER19 | rtnlndex | 2 | 14 | 2-3-4-5-6-7-9-11-12-13-14 | TCOUND20 |
TCOVER20 | rtnlndex | 9 | 14 | 2-3-4-5-6-7-9-11-12-13-14 | TCOUND21 |
TCOVER21 | lspat | 3 | 15 | 3-4-5-6-7-9-11-12-13-14-15 | TCOUND22 |
TCOVER22 | subjectLen | 4 | <6,7> | 4-5-6-7 | TCOUND23 |
TCOVER23 | subjectLen | 4 | <6,8> | 4-5-6-8 | TCOUND24 |
TCOVER24 | patternLen | 5 | <6,7> | 5-6-7 | TCOUND25 |
TCOVER25 | patternLen | 5 | <6,8> | 5-6-8 | TCOUND26 |
TCOVER26 | Ipat | 11 | 16 | 11-12-13-16 | TCOUND27 |
TCOVER27 | Ipat | 11 | <12,13> | 11-12-13 | TCOUND28 |
TCOVER28 | Ipat | 11 | <12,17> | 11-12-17 | TCOUND29 |
TCOVER29 | Ipat | 11 | <13,14> | 11-12-13-14 | TCOUND30 |
TCOVER30 | Ipat | 11 | <13,16> | 11-12-13-16 | TCOUND31 |
测试案例
用例编号 | subject[] | pattern[] | 执行路径 | 覆盖的覆盖项 | 预期输出 |
1 | {'a','b','c','d','d'} | {'a','b','c','d'} | 1-2-3--4-5-6-7-9-11-12-13-16-12-17-6-8 | TCOVER( 1, 9,11,14, 22,23,25, 27,29,30 ) | 1 |
2 | {'a','b','c','d','d'} | {'a','b','c','e'} | 1-2-3-4-5-6-7-9-11-12-13-14-15-17-6-8 | TCOVER{ 1, 3,6,9,12, 22,24,25, 28,29,31 } | -1 |
3 | {'a','b','c'} | {'a','b','c','e'} | 1-2-3-4-5-6-7-9-11-12-13-14-15-17-6-8 | TCOVER18 | -1 |
4 | {'b','b','c','d','d'} | {'a','b','c','e'} | 1-2-3-4-5-6-7-9-11-12-13-14-15-17-6-8 | TCOVER{2, 5,18,13, 19,22,25, 29} | -1 |