java Junit自动化测试框架环境搭建

junit自动化测试框架

junit框架搭建需要的jar包

  hamcrest-core-1.3.jar

  junit-4.12.jar

package test;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;


public class Test1 {
	
	@AfterClass
	public static void testAfterClass() {
		System.out.println("----------AfterClass-------------");
	}
	
	@BeforeClass
	public static void testBeforeClass() {
		System.out.println("----------BeforeClass-------------");	
	}
	
	
	@After
	public void testAfter() {
		System.out.println("----------After-------------");
	}
	
	@Before
	public void test2() {
		System.out.println("----------Before-------------");
	}
	
	@Test
	public void testADD() {
		System.out.println("----------add-------------");
	}
	
	@Test
	public void testDelete() {
		System.out.println("----------delete-------------");
	}
	
	@Ignore
	@Test
	(expected=java.lang.ArithmeticException.class,timeout=100)
	public void testIngore() {
		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
			System.out.println("----------exception-------------"+e.getMessage());	
		}
		System.out.println("----------Ignore-------------");	
	}

}

  

package test;

import org.junit.Test;

public class Test2 {

	@Test
	public void test() {
		System.out.print("-------test2-------");
	}

}

  

package test;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({Test1.class,Test2.class})

public class TestMain {
	
}

  

原文地址:https://www.cnblogs.com/wmjone/p/9565479.html