为什么要获取AssumptionViolatedException? Junit 4.8.2 [英] Why getting the AssumptionViolatedException? Junit 4.8.2

查看:283
本文介绍了为什么要获取AssumptionViolatedException? Junit 4.8.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行Junit测试.我想通过在CMS系统中请求一种方法来启动它们.因为我正在测试插件.问题是我遇到了这种异常,我不知道为什么.不,我发现问题可能是我使用的是JUnit 4.8.2,但是当我在Eclipse中运行测试时,一切正常.所以我找不到解决方案.这是错误:

I'm trying to make Junit tests. I want to start them by asking for a method in the CMS system. Because I'm testing plugins. The problem is that I get this exception and I don't know why. Naah I find that the problem could be that I'm using JUnit 4.8.2, but when I'm running the test in Eclipse everything worked fine. So I can't find the solution. Here is the error:

 org.apache.velocity.exception.MethodInvocationException: Invocation of method 
'getTest' in class nl.company.cms.three.viewtool.LoginViewTool threw exception 
java.lang.NoClassDefFoundError: org/junit/internal/AssumptionViolatedException at 
working/2a90929a-3fbf-43e9-9961-4a40279ec907_5c6e0bff-cfeb-44c6-86e2-
a0ba40e7b66c.field[line 1, column 15] 

这是我的班级和测试班级的代码: 调用以启动测试的类:

Here is the code of my class and test class: Class that calls to start the Test:

    public String getTest(){
    Result r = org.junit.runner.JUnitCore.runClasses(MyTestClass.class);
    if(r.getRunCount() > 0){
    String s = "Failcount = " + r.getFailureCount() + " // " + 
    r.getRunCount() + " in " + r.getRunTime() + " ms";
    System.out.println(r.getFailures().get(0).getTrace());
    System.out.println("Runcount: "+r.getRunCount());
    System.out.println("Runtime: "+r.getRunTime());
    System.out.println("Ignore count: "+r.getIgnoreCount());
    System.out.println("Failure count: "+ r.getFailureCount());
    return s;
}
else{
    return "Something ging kei verkeerd jonge!";
}
}

测试类:

public class MyTestClass {

@Test
public void testMultiply() {
    CustomLoginViewTool tester = new CustomLoginViewTool();
     assertEquals("Result", 40, tester.multiply(10, 5));
}

@Test
public void testMultiply1() {
    CustomLoginViewTool tester = new CustomLoginViewTool();
     assertEquals("Result", 50, tester.multiply(10, 5));
}

@Test
public void testMultiply2() {
    CustomLoginViewTool tester = new CustomLoginViewTool();
     assertEquals("Result", "ASDF", tester.multiply(10, 5));
}

@Test
public void testMultiply3() {
    CustomLoginViewTool tester = new CustomLoginViewTool();
     assertEquals("Result", 50, tester.multiply(10, 5));
}

@Test
public void testMultiply4() {
    CustomLoginViewTool tester = new CustomLoginViewTool();
     assertEquals("Result", 47, tester.multiply(10, 5));
}

@Test
public void testMultiply5() {
    CustomLoginViewTool tester = new CustomLoginViewTool();
     assertEquals("Result", 50, tester.multiply(10, 5));
}
}

推荐答案

假设是JUnit会捕获但不会使测试失败的异常.这些是针对该测试仅在以下条件下才有意义"的问题.例如,在Linux系统上通过Windows路径测试失败是没有意义的-它们无法成功,如果失败,则会给您一个错误,如果不禁用测试,您将无法修复.

Assumptions are exceptions that JUnit will catch but which won't fail the test. These are for "this test only makes sense if" kind of questions. There is no point to fail Windows-path tests on a Linux system, for example - they can't succeed and failing them will give you an error that you can't fix without disabling the tests.

我发现奇怪的是在单个错误消息中出现了Velocity和JUnit.为什么Velocity运行JUnit?

What I find odd is Velocity and JUnit in a single error message. Why is Velocity running JUnit?

该错误表示未正确设置类路径.因此,您需要查看用于加载包含方法getTest()

The error means that the classpath isn't set up correctly. So you need to look into the classloader which is used to load the class which contains the method getTest()

这篇关于为什么要获取AssumptionViolatedException? Junit 4.8.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆