如何为旅游网站店铺做推广营销,东营网站建设哪家好,ppt模板有哪些网站,网络空间maven简介 什么是maven#xff1a; maven是一款管理和构建java项目的工具#xff0c;是apache旗下的一个开源项目。 maven的作用#xff1a; 依赖管理#xff1a; 方便快捷的管理项目依赖的资源#xff08;jar包#xff09;。 项目构建#xff1a; 标准化的跨平台#…maven简介 什么是maven maven是一款管理和构建java项目的工具是apache旗下的一个开源项目。 maven的作用 依赖管理 方便快捷的管理项目依赖的资源jar包。 项目构建 标准化的跨平台LinuxwindowsmacOs的自动化项目构建方式。 统一项目结构 提供标准统一的项目结构。 maven概述 仓库 用于存储资源管理各种jar包 本地仓库自己计算机上的一个目录 中央仓库由maven团队维护的全球唯一的。仓库地址https://repo1.maven.org/maven2/ 远程仓库私服一般由公司团队搭建的私有仓库 安装 1解压 apache-maven-3.9.4-bin.zip2配置本地仓库创建一个本地仓库文件夹3修改 conf/settings.xml 中的 localRepository 为一个指定目录4配置阿里云私服修改 conf/settings.xml 中的 mirrors 标签为其添加如下子标签 mirror idalimaven/id namealiyun maven/name urlhttp://maven.aliyun.com/nexus/content/groups/public//url mirrorOfcentral/mirrorOf /mirror 5指定jdk版本 profile idjdk-21/id activation activeByDefaulttrue/activeByDefault jdk21/jdk /activation properties maven.compiler.source21/maven.compiler.source maven.compiler.target21/maven.compiler.target maven.compiler.compilerVersion21/maven.compiler.compilerVersion /properties /profile 6配置环境变量: MAVEN_HOME 为maven的解压目录并将其bin目录加入PATH环境变量 第一步解压 第二步创建本地仓库 第三步修改conf/settings.xml 第四步配置阿里云私服 第五步指定jdk版本 第六步配置环境变量 MAVEN_HOME 在path里面配置bin 测试windowr 输入mvn -v 能看见版本信息就代表成功 IDEA集成maven
第一步close Project 第二步点击 customize 右下角的 All settings 第三步点击 BuildExceptionDepliyment下面的Build Tools下面的maven进行配置 第四步点击 BuildExceptionDepliyment下面的Build Tools下面的Runner 进行配置 第五步点击 BuildExceptionDepliyment下面的 Compiler里面的java Compiler 现在IDEA已经集成maven了 创建maven项目 第一步先创建一个空项目 第二步点击在右上角的设置。找到Project Structure 第三步在project里面设置jdk版本 导入模块
第一步在新创建的工程右击 第二步选择 new Module 第三步导入module 第二步选择要导入的模块 第三步选择 import module 第四步点击pom.xml添加 第二种方式导入模块 还是点击pom.xml 移除模块
第一步点击要移除的module右击 第二步在compiler.xml删除缓存文件 maven坐标 什么是坐标 maven中的坐标是资源jar包的唯一标识通过该坐标可以唯一定位资源位置。 使用坐标来定义项目或者引入项目中需要的依赖。 maven坐标主要组成 groupId定义当前maven项目隶属组织名称通常是域名反写例如com.baidu artifactId:定义当前maven项目名称通常是模块名称例如 user-service、user-service version:定义当前项目版本号 SNAPAHOT功能不稳定处于开发中的版本即快照版本 RELEASE功能趋于稳定当前更新停止可以用于发行版本。 依赖配置 依赖指当前项目运行所需要的jar包一个项目中可以引入多个依赖。 配置 1在pom.xml中编写dependencies标签 2在dependencies标签中使用dependcy引入坐标 3定义坐标的groupIdartifiactIdversion 4点击刷新按钮引入最新的加入的坐标 示例 依赖传递 直接依赖在当前项目中通过依赖配置建立的依赖关系 间接依赖被依赖的资源如果依赖其他资源当前项目间接依赖其他资源 排除依赖指主动断开依赖的资源被排除的资源无需指定版本。 这样点就出来了 排除依赖 生命周期 maven中有三套相互独立的生命周期 clean清理工作 default核心工作如编译打包测试安装部署 site生成报告发布站点 clean操作 把已经编译好的target目录删除 compile操作编译项目出现target文件 test单元测试 package打包在target里面会出现一个jar包 install把项目打包到本地仓库 依赖范围 依赖范围的jar包默认情况下可以在任何地方使用。可以通过scope设置其作用范围。 作为范围 主程序范围有效。main文件夹范围内 测试程序范围有效。test文件夹范围内 是否参与打包运行。package指令范围内 单元测试 测试概述 是一种用来促进鉴定软件的正确性、完整性、安全性和质量的过程。 阶段划分单元测试、集成测试、系统测试、验收测试。 测试方法白盒测试、黑盒测试 及 灰盒测试。 快速入门单元测试就是针对最小的功能单元(方法)编写测试代码对其正确性进行测试。 JUnit最流行的Java测试框架之一提供了一些功能方便程序进行单元测试第三方公司提供。 使用步骤 1在pom.xml中引入Junit的依赖 2在test/java目录下创建测试类并编写对应的测试方法并在方法上声明Test注解。 3运行单元测试 (测试通过绿色测试失败红色)。 常见注解 Test测试类中的方法用它修饰才能成为测试方法才能启动执行 BeforeEach用来修饰一个实例方法该方法会在每一个测试方法执行之前执行一次。 AfterEach用来修饰一个实例方法该方法会在每一个方法执行之后执行。 BeforeAll用来修饰静态方法该方法会在所有测试方法执行之前只执行一次。 AfterAll用来修饰一个静态方法该方法会在所有实例方法之前只会执行一次。 ParameterizedTest:参数化测试的注解 (可以让单个测试运行多次每次运行时仅参数不同) ValueSource:参数化测试的参数来源赋予测试方法参数 DisplayName:指定测试类、测试方法显示的名称 默认为类名、方法名 代码示例1
package com.sde.test.test2;import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;DisplayName(用户相关的测试)
public class UserService1Test {private final String card1 610110201909091231;private final String card2 110110201509091109;private final String card3 510310198812120931;/*** 测试是否是北京*/DisplayName(测试是否是北京地区)Testpublic void testIsBeijing(){boolean flag1 new UserService().isBeijing(card1);boolean flag2 new UserService().isBeijing(card2);boolean flag3 new UserService().isBeijing(card3);System.out.println(flag1);System.out.println(flag2);System.out.println(flag3);}/*** 测试年龄*/DisplayName(测试用户的年龄)Testpublic void testGetAge(){Integer age1 new UserService().getAge(card1);Integer age2 new UserService().getAge(card2);Integer age3 new UserService().getAge(card3);System.out.println(age1);System.out.println(age2);System.out.println(age3);}/*** 测试性别*/DisplayName(测试用户的性别)Testpublic void testGetGender(){String gender1 new UserService().getGender(card1);String gender2 new UserService().getGender(card2);String gender3 new UserService().getGender(card3);System.out.println(gender1);System.out.println(gender2);System.out.println(gender3);}/*** 测试出生年份*/DisplayName(测试出生年份)Testpublic void testYear(){String year1 new UserService().getYear(card1);String year2 new UserService().getYear(card2);String year3 new UserService().getYear(card3);System.out.println(year1);System.out.println(year2);System.out.println(year3);}/*** 测试出生月份*/DisplayName(测试出生月份)Testpublic void testGetMonth(){String month1 new UserService().getMonth(card1);String month2 new UserService().getMonth(card2);String month3 new UserService().getMonth(card3);System.out.println(month1);System.out.println(month2);System.out.println(month3);}}测试案例2
package com.sde.test.test2;import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;DisplayName(用户相关的测试)
public class UserService2Test {DisplayName(测试是否是北京地区)ParameterizedTestValueSource(strings {610110201909091231,110110201509091109,510310198812120931})public void testIsBeijing(String cardId){boolean b new UserService().isBeijing(cardId);System.out.println(b);}DisplayName(测试用户的年龄)ParameterizedTestValueSource(strings {610110201909091231,110110201509091109,510310198812120931})public void testGetAge(String cardId){Integer age new UserService().getAge(cardId);System.out.println(age);}DisplayName(测试用户的性别)ParameterizedTestValueSource(strings {610110201909091231,110110201509091109,510310198812120931})public void testGetGender(String cardId){String gender new UserService().getGender(cardId);System.out.println(gender);}DisplayName(测试出生年份)ParameterizedTestValueSource(strings {610110201909091231,110110201509091109,510310198812120931})public void testGetYear(String cardId){String year new UserService().getYear(cardId);System.out.println(year);}DisplayName(测试出生月份)ParameterizedTestValueSource(strings {610110201909091231,110110201509091109,510310198812120931})public void testGetMonth(String cardId){String month new UserService().getMonth(cardId);System.out.println(month);}}案例3
package com.sde.test.test2;import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;DisplayName(用户相关的测试)
public class UserServer3Test {private final String card1 610110201909091231;private final String card2 110110201509091109;private final String card3 510310198812120931;/*** 测试是否是北京*/DisplayName(测试是否是北京地区)Testpublic void testIsBeijing(){boolean flag1 new UserService().isBeijing(card1);boolean flag2 new UserService().isBeijing(card2);boolean flag3 new UserService().isBeijing(card3);System.out.println(flag1);System.out.println(flag2);System.out.println(flag3);Assertions.assertFalse(flag1);Assertions.assertTrue(flag2);Assertions.assertFalse(flag3);}/*** 测试年龄*/DisplayName(测试用户的年龄)Testpublic void testGetAge(){Integer age1 new UserService().getAge(card1);Integer age2 new UserService().getAge(card2);Integer age3 new UserService().getAge(card3);System.out.println(age1);System.out.println(age2);System.out.println(age3);Assertions.assertEquals(4,age1,4岁);Assertions.assertEquals(8,age2,8岁);Assertions.assertEquals(34,age3,34岁);}/*** 测试性别*/DisplayName(测试用户的性别)Testpublic void testGetGender(){String gender1 new UserService().getGender(card1);String gender2 new UserService().getGender(card2);String gender3 new UserService().getGender(card3);System.out.println(gender1);System.out.println(gender2);System.out.println(gender3);Assertions.assertEquals(男,gender1,男);Assertions.assertEquals(女,gender2,女);Assertions.assertEquals(男,gender3,男);}/*** 测试出生年份*/DisplayName(测试出生年份)Testpublic void testYear(){String year1 new UserService().getYear(card1);String year2 new UserService().getYear(card2);String year3 new UserService().getYear(card3);System.out.println(year1);System.out.println(year2);System.out.println(year3);Assertions.assertEquals(2019,year1,2019);Assertions.assertEquals(2015,year2,2015);Assertions.assertEquals(1988,year3,1988);}/*** 测试出生年份*/DisplayName(测试出生月份)Testpublic void testGetMonth(){String month1 new UserService().getMonth(card1);String month2 new UserService().getMonth(card2);String month3 new UserService().getMonth(card3);System.out.println(month1);System.out.println(month2);System.out.println(month3);Assertions.assertEquals(09,month1,09);Assertions.assertEquals(09,month2,09);Assertions.assertEquals(12,month3,12);}
}断言 assertEquals(Object exp, Object act, String msg)---检查两个值是否相等不相等就报错。 assertNotEquals(Object unexp, Object act, String msg)---检查两个值是否不相等相等就报错。 assertNull(Object act, String msg)--- 检查对象是否为null不为null就报错。 assertNotNull(Object act, String msg)---检查对象是否不为null为null就报错。 assertTrue(boolean condition, String msg)---检查条件是否为true不为true就报错。 assertFalse(boolean condition, String msg)---检查条件是否为false不为false就报错。 assertSame(Object exp, Object act, String msg)---检查两个对象引用是否相等不相等就报错。 案例
package com.sde.test.test2;import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;DisplayName(用户相关的测试)
public class UserServer3Test {private final String card1 610110201909091231;private final String card2 110110201509091109;private final String card3 510310198812120931;/*** 测试是否是北京*/DisplayName(测试是否是北京地区)Testpublic void testIsBeijing(){boolean flag1 new UserService().isBeijing(card1);boolean flag2 new UserService().isBeijing(card2);boolean flag3 new UserService().isBeijing(card3);System.out.println(flag1);System.out.println(flag2);System.out.println(flag3);Assertions.assertFalse(flag1);Assertions.assertTrue(flag2);Assertions.assertFalse(flag3);}/*** 测试年龄*/DisplayName(测试用户的年龄)Testpublic void testGetAge(){Integer age1 new UserService().getAge(card1);Integer age2 new UserService().getAge(card2);Integer age3 new UserService().getAge(card3);System.out.println(age1);System.out.println(age2);System.out.println(age3);Assertions.assertEquals(4,age1,4岁);Assertions.assertEquals(8,age2,8岁);Assertions.assertEquals(34,age3,34岁);}/*** 测试性别*/DisplayName(测试用户的性别)Testpublic void testGetGender(){String gender1 new UserService().getGender(card1);String gender2 new UserService().getGender(card2);String gender3 new UserService().getGender(card3);System.out.println(gender1);System.out.println(gender2);System.out.println(gender3);Assertions.assertEquals(男,gender1,男);Assertions.assertEquals(女,gender2,女);Assertions.assertEquals(男,gender3,男);}/*** 测试出生年份*/DisplayName(测试出生年份)Testpublic void testYear(){String year1 new UserService().getYear(card1);String year2 new UserService().getYear(card2);String year3 new UserService().getYear(card3);System.out.println(year1);System.out.println(year2);System.out.println(year3);Assertions.assertEquals(2019,year1,2019);Assertions.assertEquals(2015,year2,2015);Assertions.assertEquals(1988,year3,1988);}/*** 测试出生年份*/DisplayName(测试出生月份)Testpublic void testGetMonth(){String month1 new UserService().getMonth(card1);String month2 new UserService().getMonth(card2);String month3 new UserService().getMonth(card3);System.out.println(month1);System.out.println(month2);System.out.println(month3);Assertions.assertEquals(09,month1,09);Assertions.assertEquals(09,month2,09);Assertions.assertEquals(12,month3,12);}
}