美文网首页NJUPT 计软院 复习资料
NJUPT《软件工程(双语)》

NJUPT《软件工程(双语)》

作者: Du1in9 | 来源:发表于2022-05-24 13:07 被阅读0次

    1/3 考前复习

    复习课笔记
    https://wwb.lanzouh.com/iMVah06936ej

    2/3 课堂练习

    https://wwb.lanzouh.com/iWBdl05qw75g
    https://wwb.lanzouh.com/ieaYZ05yjpti
    https://wwb.lanzouh.com/i47ze05cy8je

    3/3 实验报告

    实验三:Software Unit Testing
    • 实验目的和要求

    对 Java 单元测试有初步的了解,学会使用 Junit 编写自己的测试用例,掌握对被测试类进行测试的实现方法;了解轻量级的自动化工具 Selenium,学会使用 Selenium 进行网站自动化测试(选做)。

    • 实验环境

    Eclipse、jdk1.8、chrome browser

    • 实验步骤

    利用 Junit 编写测试用例,并对被测试类进行相关功能测试。
    a) 验证 Book 类的 equals 方法;

    Book.java:
    
    
    package cn.edu.njupt;
    public class Book {
        private String title;
        private double price;
        public Book(String title, double price) {
            this.title = title;
            this.price = price;
        }
        public boolean equals(Object object) {
            if(object instanceof Book){
                Book book=(Book)object;
                return getTitle().equals(book.getTitle())
                        && getPrice()==book.getPrice();
            }
            return false;
        }
        public String getTitle() {
            return title;
        }
        public void setTitle(String title) {
            this.title = title;
        }
        public double getPrice() {
            return price;
        }
        public void setPrice(double price) {
            this.price = price;
        }
    }
    
    BookTest.java:
    
    
    package cn.edu.njupt;
    import org.junit.jupiter.api.AfterEach;
    import org.junit.jupiter.api.BeforeEach;
    import org.junit.jupiter.api.Test;
    import static org.junit.jupiter.api.Assertions.*;
    class BookTest {
        private Book book1;
        private Book book2;
        @BeforeEach
        void setUp() {
            book1=new Book("ES",12.99);
            book2=new Book("The Grate",11.99);
        }
        @AfterEach
        void tearDown() {
            book1=null;
            book2=null;
        }
        @Test
        void testEquals() {
            assertFalse((book2.equals(book1)));
            assertTrue((book1.equals(book1)));
        }
    }
    

    B)设计 Triangle 类的测试用例,并进行测试。


    Triangle.java:
    
    
    package cn.edu.njupt;
    public class Triangle {
        protected long lborderA=0;
        protected long lborderB=0;
        protected long lborderC=0;
        public Triangle(long lborderA, long lborderB, long lborderC) {
            this.lborderA = lborderA;
            this.lborderB = lborderB;
            this.lborderC = lborderC;
        }
        public static boolean isTriangle(Triangle triangle){
            boolean isTriangle=false;
            if((triangle.lborderA>0 && triangle.lborderA<=Long.MAX_VALUE/2)
                    &&(triangle.lborderB>0 && triangle.lborderB<=Long.MAX_VALUE/2)
                    &&(triangle.lborderC>0 && triangle.lborderC<=Long.MAX_VALUE/2))
                if((triangle.lborderA < (triangle.lborderB+triangle.lborderC))
                        &&(triangle.lborderB < (triangle.lborderA+triangle.lborderC))
                        &&(triangle.lborderC < (triangle.lborderB+triangle.lborderA)))
                        isTriangle=true;
            return isTriangle;
        }
    
        public static String getType(Triangle triangle){
            String strType="不是三角形";
            if(isTriangle(triangle)){
                if(triangle.lborderA==triangle.lborderB
                    && triangle.lborderB==triangle.lborderC){
                    strType="等边三角形";
                }
                else if((triangle.lborderA !=triangle.lborderB)
                    &&(triangle.lborderB !=triangle.lborderC)
                    &&(triangle.lborderA !=triangle.lborderC))
                    strType="不等边三角形";
                else{
                    strType="等腰三角形";
                }
            }
            return strType;
        }
    }
    
    TriangleTest.java:
    
    
    package cn.edu.njupt;
    import org.junit.jupiter.api.AfterEach;
    import org.junit.jupiter.api.BeforeEach;
    import org.junit.jupiter.api.Test;
    import static org.junit.jupiter.api.Assertions.*;
    class TriangleTest {
        private Triangle triangle1;
        private Triangle triangle2;
        private Triangle triangle3;
        private Triangle triangle4;
        private Triangle triangle5;
        private Triangle triangle6;
        @BeforeEach
        void setUp() {
            triangle1=new Triangle(3,3,3);
            triangle2=new Triangle(3,4,5);
            triangle3=new Triangle(3,3,5);
            triangle4=new Triangle(-1,3,5);
            triangle5=new Triangle(3,10,5);
            triangle6=new Triangle(3,3,5);
        }
        @AfterEach
        void tearDown() {
            triangle1=null;
            triangle2=null;
            triangle3=null;
            triangle4=null;
            triangle5=null;
            triangle6=null;
        }
        @Test
        void isTriangle() {
            assertTrue(Triangle.isTriangle(triangle6));
            assertFalse(Triangle.isTriangle(triangle4));
            assertFalse(Triangle.isTriangle(triangle5));
        }
        @Test
        void getType() {
            assertEquals("等边三角形",Triangle .getType(triangle1));
            assertEquals("不等边三角形",Triangle.getType(triangle2));
            assertEquals("等腰三角形",Triangle.getType(triangle3));
            assertEquals("不是三角形",Triangle.getType(triangle4));
        }
    }
    

    4、利用 Selenium 进行 Web 应用程序的自动化测试。(选做)
    A)导入Selenium的jar包



    B)下载对应Chrome浏览器版本的驱动



    (要修改Demo.java中对应的路径)
    C)编写demo类:
    package king.test;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import java.util.List;
    import java.util.concurrent.TimeUnit;
    public class Demo1 {
        private WebDriver driver;
    
        @Before
        public void setUp(){
            //设置谷歌浏览器的驱动
            System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
            //启动谷歌浏览器
            driver=new ChromeDriver();
            //设置默认超时时间
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        }
        @After
        public void tearDown() throws Exception{
            //关闭浏览器
            driver.quit();
        }
        @Test
        public void test222() throws Exception{
            //打开测试页面
            driver.get("file:///E:/test.html");
            //通过id找到第一个输入框
            WebElement un =driver.findElement(By.id("un"));
            //第一个输入框输入aaa
            un.sendKeys("aaa");
            //通过id找到第二个输入框
            WebElement pw =driver.findElement(By.className("lala"));
            //第一个输入框输入bbb
            pw.sendKeys("bbb");
            //通过id找到第三个输入框
            WebElement co =driver.findElement(By.name("code"));
            //第一个输入框输入ccc
            co.sendKeys("ccc");
            Thread.sleep(2000);
            //找到页面中的所有的input标签
            List<WebElement> inputs=driver.findElements(By.tagName("input"));
            //获取第四个input标签
            WebElement btn = inputs.get(3);
            //点击按钮
            btn.click();
            Thread.sleep(3000);
        }
    }
    

    编写演示页面:test.html(要修改Demo.java中对应的路径)


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="Generator" content="EditPlus®">
        <meta name="Author" content="">
        <meta name="Keywords" content="">
        <meta name="Description" content="">
        <title>Document</title>
    </head>
    <body>
        <input id="un" class="css1" name="username">
        <input id="pw" class="css2 lala" name="password">
        <input id="co" class="css3" name="code"><br>
        <input type="button" id="btn" class="css4" name="submit" value="按钮">
        <script>
            document.getElementById('btn').onclick=function(){
                alert("haha");
            }
        </script>
    </body>
    </html>
    
    实验四:Software Configuration management
    • 实验目的和要求

    学会配置Visual SVN Server服务器与用户、用户组和权限,学会用客户端链接服务器端,掌握SVN 常用功能操作完成 svn 的添加、提交、更新、分支建立、合并等操作。

    • 实验环境

    1、服务器端:Windows XP
    XP 系统安装:https://www.jianshu.com/p/419eff3d6235
    Visual SVN Server 选择老版本 2.7.5,下载链接:https://www.visualsvn.com/files/VisualSVN-Server-2.7.5.msi
    2、客户端:Windows 10
    TortoiseSVN 选择 WIN 32版本1.10.6 ,下载链接:https://tortoisesvn.net/downloads.html

    • 实验步骤

    1、安装服务器端 Visual SVN Server



    2、配置 SVN 服务器的用户、用户组和权限



    3、客户端链接服务器端

    4、SVN 常用功能操作
    完成 svn 的添加、提交、更新、分支、合并等操作。


    image.png

    相关文章

      网友评论

        本文标题:NJUPT《软件工程(双语)》

        本文链接:https://www.haomeiwen.com/subject/bkklprtx.html