public abstract class Runner implements Describable {
public abstract Description getDescription();
public abstract void run(RunNotifier notifier);
public int testCount() {
return getDescription().testCount();
}
}
private final Object[] parameters;
private final String name;
public BlockJUnit4ClassRunnerWithParameters(TestWithParameters test)
throws InitializationError {
super(test.getTestClass().getJavaClass());
parameters = test.getParameters().toArray(
new Object[test.getParameters().size()]);
name = test.getName();
}
参数代码如下:
public class TestWithParameters {
private final String name;
private final TestClass testClass;
private final List
@RunWith(Suite.class)
@Suite.SuiteClasses({Suite_test_a.class,Suite_test_b.class,Suite_test_c.class })
public class Suite_main {
}
public class Suite_test_a {
@Test
public void testRun(){
System.out.println("Suite_test_a_running");
}
}
public class Suite_test_b {
@Test
public void testRun(){
System.out.println("Suite_test_b_running");
}
}
public class Suite_test_c {
@Test
public void testRun(){
System.out.println("Suite_test_c_running");
}
}
public interface BlackCategory {}
public interface WhiteCategory {}
public class Categories_test_a {
@Test
@Category(BlackCategory.class)
public void testFirst(){
System.out.println("Categories_test_a_testFirst_running");
}
@Test
@Category(WhiteCategory.class)
public void testSecond(){
System.out.println("Categories_test_a_testSecond_running");
}
}
public class Categories_test_b {
@Test
@Category(WhiteCategory.class)
public void testFirst(){
System.out.println("Categories_test_b_testFirst_running");
}
@Test
@Category(BlackCategory.class)
public void testSecond(){
System.out.println("Categories_test_b_testSecond_running");
}
}
执行带WhiteCategory的方法
@RunWith(Categories.class)
@Categories.IncludeCategory(WhiteCategory.class)
@Categories.ExcludeCategory(BlackCategory.class)
@Suite.SuiteClasses( { Categories_test_a.class, Categories_test_b.class })
public class Categories_main {
}
运行结果:
图4 Categories测试代码WhiteCategory分组执行结果
执行带BlackCategory的方法
@RunWith(Categories.class)
@Categories.IncludeCategory(BlackCategory.class)
@Categories.ExcludeCategory(WhiteCategory.class)
@Suite.SuiteClasses( { Categories_test_a.class, Categories_test_b.class })
public class Categories_main {
}
public class EnclosedTest {
@Test
public void runOutMethou(){
System.out.println("EnclosedTest_runOutMethou_running");
}
public static class EnclosedInnerTest {
@Test
public void runInMethou(){
System.out.println("EnclosedInnerTest_runInMethou_running");
}
}
}
运行结果:没有执行内部类的测试方法。
图6 Enclosed测试代码的执行结果
使用Enclosed执行器:
@RunWith(Enclosed.class)
public class EnclosedTest {
@Test
public void runOutMethou(){
System.out.println("EnclosedTest_runOutMethou_running");
}
public static class EnclosedInnerTest {
@Test
public void runInMethou(){
System.out.println("EnclosedInnerTest_runInMethou_running");
}
}
}
private final List causes;
public ErrorReportingRunner(Class> testClass, Throwable cause) {
if (testClass == null) {
throw new NullPointerException("Test class cannot be null");
}
this.testClass = testClass;
causes = getCauses(cause);
}
private List getCauses(Throwable cause) {
if (cause instanceof InvocationTargetException) {
return getCauses(cause.getCause());
}
if (cause instanceof InitializationError) {
return ((InitializationError) cause).getCauses();
}
if (cause instanceof org.junit.internal.runners.InitializationError) {
return ((org.junit.internal.runners.InitializationError) cause)
.getCauses();
}
return Arrays.asList(cause);
}
当junit运行错误时,会抛出ErrorReportingRunner,例如:
public Runner getRunner() {
try {
Runner runner = request.getRunner();
fFilter.apply(runner);
return runner;
} catch (NoTestsRemainException e) {
return new ErrorReportingRunner(Filter.class, new Exception(String
.format("No tests found matching %s from %s", fFilter
.describe(), request.toString())));
}
}
3.4 IgnoredClassRunner
IgnoredClassRunner是当测试的方法包含Ignore注解时,会忽略该方法。
public class IgnoredClassRunner extends Runner {
private final Class> clazz;
public IgnoredClassRunner(Class> testClass) {
clazz = testClass;
}
@Override
public void run(RunNotifier notifier) {
notifier.fireTestIgnored(getDescription());
}
@Override
public Description getDescription() {
return Description.createSuiteDescription(clazz);
}
}
IgnoredClassRunner的使用
public class IgnoredBuilder extends RunnerBuilder {
@Override
public Runner runnerForClass(Class> testClass) {
if (testClass.getAnnotation(Ignore.class) != null) {
return new IgnoredClassRunner(testClass);
}
return null;
}
}
访问权限是java中一个比较中要的知识点,它规定者什么方法可以访问,什么不可以访问
一:包访问权限;
自定义包:
package com.wj.control;
//包
public class Demo {
//定义一个无参的方法
public void DemoPackage(){
System.out.println("调用
用户自定义聚合函数,用户提供的多个入参通过聚合计算(求和、求最大值、求最小值)得到一个聚合计算结果的函数。
问题:UDF也可以提供输入多个参数然后输出一个结果的运算,比如加法运算add(3,5),add这个UDF需要实现UDF的evaluate方法,那么UDF和UDAF的实质分别究竟是什么?
Double evaluate(Double a, Double b)
在利用tomcat-redis-session-manager做session同步时,遇到了在session保存一个自定义对象时,修改该对象中的某个属性,session未进行序列化,属性没有被存储到redis中。 在 tomcat-redis-session-manager的github上有如下说明: Session Change Tracking
As noted in the &qu
关于Table Driven Approach的一篇非常好的文章:
http://www.codeproject.com/Articles/42732/Table-driven-Approach
package com.ljn.base;
import java.util.Random;
public class TableDriven {
public