Bean的注解方式装配
Bean的注解方式装配 1. 使用注解方式注入 需要引入 context 名称空间 xmlns:context="http:…
public void
进行修饰,不能带任何的参数测试用例是不用来证明你是对的,而是用来证明你没有错
测试用例用来达到想要的预期结果,但对于逻辑错误无能为力
@BeforeClass
修饰的方法会在所有方法被调用前被执行,而且该方法是静态的,所以当测试类被加载后接着就会运行它,而且内存中它只会存在一份实例,它比较适合加载配置文件。@AfterClass
所修饰的方法通常用来对资源进行清理,如关闭数据库连接等@Before
和@After
会在每个测试方法的前后各执行一次。@Test(expected=XX.class)
: 捕获什么异常@Test(timeout=毫秒值)
:超时退出@Ignore
:所修饰的测试方法会被测试运行器忽略@RunWith
:可以更改测试运行器 org.junit.runner.Runner测试套件就是组织测试类一起运行的
Suite.class
Suite,SuiteClasses({ })
中SuiteTest:
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
* Created By liuyao on 2018/5/10 0:10.
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({TaskTest1.class, TaskTest2.class})
public class SuiteTest {
}
TaskTest1:
import org.junit.Test;
/**
* Created By liuyao on 2018/5/10 0:10.
*/
public class TaskTest1 {
@Test
public void test1() {
System.out.println("TaskTest1");
}
}
Test2与Test1类似
测试结果:
Calclute:
public class Calclute {
public int add(int i, int j) {
return i + j;
}
}
Parameter:
package com.liuyao.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collection;
/**
* Created By liuyao on 2018/5/10 0:19.
*/
@RunWith(Parameterized.class)
public class ParameterTest {
int expected = 0;
int input1 = 0;
int input2 = 0;
@Parameterized.Parameters
public static Collection<Object[]> t() {
return Arrays.asList(new Object[][]{
{3, 1, 2},
{4, 2, 2}
});
}
public ParameterTest(int expected, int input1, int input2) {
this.expected = expected;
this.input1 = input1;
this.input2 = input2;
}
@Test
public void test() {
assertEquals(this.expected, new Calclute().add(this.input1, this.input2));
}
}
测试结果:
Bean的注解方式装配 1. 使用注解方式注入 需要引入 context 名称空间 xmlns:context="http:…
锁与并发 1. 对象头和锁 在Java虚拟机每个对象都有一个对象头,用于保存对象的系统信息。对象头中有一个Mark Word的部分,它是实现锁的关键。32位系统中占32位,64位系统占64位。…