@RunWith(Suite.class)
@Suite.SuiteClasses({AssertTests.class, CalculatorTest.class})
public class SuiteTest {
// the class remains empty, used only as a holder for the above annotations
}
public class AssumptionsTest {
@Test
public void testAssumTrue() {
System.out.println("test");
assumeTrue(3>5);
//该方法中下面所有的代码在上面假设的条件成立后执行
//如果上述假设不成立,则会忽略执行该行下面的代码,并报错
System.out.println("assume is true!");
}
@Test
public void testAssumFalse(){
assumeFalse(3>5);
System.out.println("assume is true!");
}
}
以下语法JUnit5支持:
@Test
public void testAssumTrueMessage() {
assumeTrue(3<5,
//第二个参数为当第一个参数不成立时,输出的自定义错误信息
() -> "Aborting test: not on developer workstation");
System.out.println("assume is true!");
}
@Test
public void testAssumeTrueLambda(){
//这个方法的第一个参数为函数式接口,无参数返回值为boolean
assumeTrue(()->{
System.out.println("in assumeTrue");
boolean flag = false;
return flag;
});
System.out.println("out assumeTrue");
}
@Test
public void testAssumThat() {
assumingThat(3>5,
() -> {
//与上述方法不同的是,仅当前面假设成立时,才会执行这里面的语句
//且只会影响到该lambda表达式中的代码
assertEquals(2, 2);
});
//此处的断言不受上述assumingThat限制,在所有情况下都会执行
System.out.println("no effect");
assertEquals("a string", "a string");
}
@Retention(RetentionPolicy.RUNTIME)
// 声明注解接口所使用的委托处理类
@ParametersSuppliedBy(BetweenSupplier.class)
public @interface Between{
// 声明所有可用参数,效果为 @Between([first = int,] last = int)
int first() default 0; // 声明默认值
int last();
}
(2)定义委托处理类 BetweenSupplier
public class BetweenSupplier extends ParameterSupplier {
@Override
public List getValueSources(ParameterSignature sig) {
// 自定义实参值列表
List list = new ArrayList();
// 获取注解变量
Between between = sig.getAnnotation(Between.class);
// 获取通过注解@Between传入的first值
int first = between.first();
// 获取通过注解@Between传入的last值
int last = between.last();
for (int i = first; i <= last; i++) {
// PotentialAssignment.forValue(String name, Object value)
// name为value的描述标记,没实际作用
// value为实参可选值
list.add(PotentialAssignment.forValue("name", i));
}
return list;
}
}
(3)调用方式
@RunWith(Theories.class)
public class TheoryDefinedTest {
@Theory
public final void test(@Between(last = 0) int i, @Between(first = 3, last= 10) int j) {
// i 取值为 0(first默认=0,last=0),j 取值为 3-10
System.out.println("i="+i+" j="+j);
}
}
public class FixtureTest {
private static int quantity = 0;
public FixtureTest() {
quantity++;
}
@BeforeClass
public static void breforeTestOnlyOnce() throws Exception {
System.out.println("Run before all test only once..."+ quantity);
}
@AfterClass
public static void afterTestOnlyOnce() throws Exception {
System.out.println("Run after all test only once..."+ quantity);
}
@Before
public void beforePerTest() {
System.out.println("Run before per test ..."+ quantity);
}
@After
public void afterPerTest() {
System.out.println("Run after per test ..."+ quantity);
}
//Test Method
@Test
public void testOne() {
System.out.println("testOne Start..."+ quantity);
}
@Test
public void testTwo() {
System.out.println("testTwo Start..."+ quantity);
}
}
运行结果:
Run before all test only once...0
Run before per test ...1
testOne Start...1
Run after per test ...1
Run before per test ...2
testTwo Start...2
Run after per test ...2
Run after all test only once...2
public interface FastTests { /* category marker */ }
public interface SlowTests { /* category marker */ }
public class A {
@Test
public void a() {
fail();
}
@Category(SlowTests.class)
@Test
public void b() {
}
}
@Category({SlowTests.class, FastTests.class})
public class B {
@Test
public void c() {
}
}
@RunWith(Categories.class)
@IncludeCategory(SlowTests.class)
@SuiteClasses( { A.class, B.class }) // Note that Categories is a kind of Suite
public class SlowTestSuite {
// Will run A.b and B.c, but not A.a
}
@RunWith(Categories.class)
@IncludeCategory(SlowTests.class)
@ExcludeCategory(FastTests.class)
@SuiteClasses( { A.class, B.class }) // Note that Categories is a kind of Suite
public class SlowTestSuite {
// Will run A.b, but not A.a or B.c
}
如果在使用JAXB把xml文件unmarshal成vo(XSD自动生成的vo)时碰到如下错误:
org.xml.sax.saxparseexception : premature end of file
很有可能时你直接读取文件为inputstream,然后将inputstream作为构建unmarshal需要的source参数。InputSource inputSource = new In
servlet 搞java web开发的人一定不会陌生,而且大家还会时常用到它。
下面是java官方网站上对servlet的介绍: java官网对于servlet的解释 写道
Java Servlet Technology Overview Servlets are the Java platform technology of choice for extending and enha
这两天学到事务管理这一块,结合到之前的terasoluna框架,觉得书本上讲的还是简单阿。我就把我从书本上学到的再结合实际的项目以及网上看到的一些内容,对声明式事务管理做个整理吧。我看得Spring in Action第二版中只提到了用TransactionProxyFactoryBean和<tx:advice/>,定义注释驱动这三种,我承认后两种的内容很好,很强大。但是实际的项目当中
1)nosql数据库主要由以下特点:非关系型的、分布式的、开源的、水平可扩展的。
1,处理超大量的数据
2,运行在便宜的PC服务器集群上,
3,击碎了性能瓶颈。
1)对数据高并发读写。
2)对海量数据的高效率存储和访问。
3)对数据的高扩展性和高可用性。
redis支持的类型:
Sring 类型
set name lijie
get name lijie
set na
在多节点的系统中,如何实现分布式锁机制,其中用redis来实现是很好的方法之一,我们先来看一下jedis包中,有个类名BinaryJedis,它有个方法如下:
public Long setnx(final byte[] key, final byte[] value) {
checkIsInMulti();
client.setnx(key, value);
ret