美文网首页JAVA学习过程
JAVA学习入门之Eclips使用

JAVA学习入门之Eclips使用

作者: _String_ | 来源:发表于2017-09-19 16:01 被阅读0次

    Eclips常用快捷键

    alt + / 内容提示
    ctrl +1 快速修复
    导包: ctrl + shift +O
    格式化代码: ctrl + shift +F
    向前向后: alt + 方向键
    添加注释: ctrl +shift +/
    除去注释:ctrl + shift +
    程序的调试和运行
    F5跳入 F6跳过 F7跳出

    Junit 测试方法

    新建类后可以通过新建测试类在测试方法生命行的上面加上@Test并导入Junit类即可运行是选择Junit测试。测试结果如图:

    Junit测试成功

    附上测试代码如下:

    package hello;
    
    public class cc {
        public void XSS()
        {
            System.out.println("XSS");
        }
        public void Sql()
        {
            System.out.println("SQL");
        }
    
    }
    

    测试类内容如下:

    package hello;
    
    import org.junit.Test;
    
    public class run {
        @Test
        public void ttten()
        {
             cc c = new cc();
             c.XSS();
             c.Sql(); 
    
        }
    
    }
    

    Junit测试可以通过选择某个函数单独测试指定函数,如下图:

    单独测试DVD类

    DVD类代码如下:

    package hello;
    
    public class DVD extends Item{
    
        
        private String director;
        
    
        
        
    
        public DVD(String title, String director, int playingTime, String comment) {
            
            //super();
            super(title,playingTime,comment);
            
            
            this.director = director;
    //      this.playingTime = playingTime;
    //      this.comment = comment;
        }
    
    
        public void print() {
            // TODO Auto-generated method stub
            super.print();
            System.out.println("==============="+director);
            
        }
    
    }
    

    Junit测试可以使用@before参数,使其每个测试函数在开始前先执行before函数里定义的内容代码。
    After 在测试代码执行后会自动执行After声明的代码如图:

    Before及After输出结果

    参考代码如下:

    package hello;
    
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    
    public class run {
        
        @Before
        public void fast()
        {
            System.out.println("fast");
        }
        @Test
        public void ttten()
        {
             cc c = new cc();
             c.XSS();
             c.Sql(); 
    
        }
        @Test
        public  void runDVD()
        {
            
            DVD dvd=new DVD("dvd1", "DVD fast 1", 90, "bbbbbbbb");
            dvd.print();
            dvd.check();
    
        }
        @After
        public void showx()
        
        {
            System.out.print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
        }
    
    }
    

    相关文章

      网友评论

        本文标题:JAVA学习入门之Eclips使用

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