zoukankan      html  css  js  c++  java
  • java单元测试

    单元测试

    步骤:

    • 1.选中当前工程–右键选择: build path - add libraries - JUnit 4 -下一步-
    • 2.创建Java类,进行单元测试。
      此时的Java类要求:①此类是public的 ②此类提供公共的无参的构造器
    • 3.此类中声明单元测试方法。
      此时的单元测试方法:方法的权限是public,没有返回值,没有形参
    • 4.此单元测试方法上需要声明注解:@Test,并在单元测试类中导入:import org.junit.Test;

    说明:
    1.如果执行结果没有任何异常:绿条
    2.如果执行结果出现异常:红条

    package oop.unittest;
    
    import org.junit.Test;
    
    /*
     * 步骤:
    1.选中当前工程–右键选择: build path - add libraries - JUnit 4 -下一步
    2.创建Java类,进行单元测试。
         此时的Java类要求:①此类是public的 ②此类提供公共的无参的构造器
    3.此类中声明单元测试方法。
         此时的单元测试方法:方法的权限是public,没有返回值,没有形参
    4.此单元测试方法上需要声明注解:@Test,并在单元测试类中导入:import org.junit.Test;
    
    说明:
    1.如果执行结果没有任何异常:绿条
    2.如果执行结果出现异常:红条
    
    
     */
    public class JUnitTest {
    	int num = 20;
    	
    	@Test
    	public void testEquals() {
    		String s1 = "hello";
    		String s2 = "hello";
    		System.out.println(s1 == s2);
    		
    		show();
    		System.out.println(num);
    	}
    	
    	public void show() {
    		num = 30;
    		System.out.println("show()");
    	}
    	
    	@Test
    	public void testToString() {
    		String s = "hello";
    		System.out.println(s);
    	}
    }
    
    点个推荐再走吧
  • 相关阅读:
    Advanced Configuration Tricks
    Reviewing the Blog Module
    Editing and Deleting Data
    Making Use of Forms and Fieldsets
    Understanding the Router
    SQL Abstraction and Object Hydration
    Preparing for Different Databases
    Java学习理解路线图
    Openstack学习历程_1_视频
    CentOS安装Nginx负载
  • 原文地址:https://www.cnblogs.com/victorxiao/p/14613288.html
Copyright © 2011-2022 走看看