Tag: 测试

在eclipse中运行JUnit测试后,我可以以XML格式导出结果。 如何使用JUnit命令行获取该xml文件?

我有Javaunit testing,我在Eclipse中使用JUnit插件运行。 在eclipse中完成所有测试后,我可以将结果导出为.xml格式,我将其用于将结果上传到测试结果跟踪工具中。 现在我在AIX系统中运行相同的测试,我使用命令行来运行JUnit测试。 我的命令是 java org.junit.runner.JUnitCore com.rsa.qa.sae.test.testClassName 现在我想在类似的XML文件中获得这些测试的结果。 我怎么才能得到它?

检查JUnit中的exception的最佳做法是什么?

我正在努力编写测试用例。 根据我的阅读,我的测试应该从一开始就失败,我应该努力让测试通过。 但是,我发现自己编写测试检查边界以及它们应该导致的exception: @Test(expected=NegativeArraySizeException.class) public void testWorldMapIntInt() { WorldMap w = new WorldMap(-1, -1); } @Test(expected=IndexOutOfBoundsException.class) public void testGetnIntnInt() { WorldMap w = new WorldMap(10,10); Object o = w.get(-1, -1); } 但是,此测试默认情况下会通过,因为Java无论如何都会抛出exception。 有没有更好的方法来处理这些预期的exception,可能是默认情况下失败的方式 – 迫使我努力处理这些情况?

插入排序,MergeSort和快速排序的测试用例

我已经实现了(在Java中)Insertion Sort,MergeSort,ModifiedMergeSort和Quick Sort: ModifiedMergeSort具有元素“绑定”的变量。 当要排序的元素小于或等于“bound”时,请使用Insertion Sort对它们进行排序。 为什么版本1比版本3,4和5更好? 版本2和6的结果是否真实? 这是我的结果(以毫秒为单位): Version 1 – Insertion Sort: Run-Times over 50 test runs Input Size Best-Case Worst-Case Average-Case N = 10000 14 19 14.96 N = 20000 59 60 59.3 N = 40000 234 277 243.1 Version 2 – Merge Sort: Run-Times over 50 test runs Input Size Best-Case […]

没有源代码的Android应用程序中的方法覆盖

没有源代码,有人能给我一个关于android apks中方法覆盖的ide吗? 我听说有一个Android特定版本的emma项目可以通过仪器提供方法覆盖信息。 但如果我没有源代码,我该如何设置代码呢? 我的目标是在运行应用程序时如何获取运行时调用哪些方法的报告。

关于create activity的Robolectric 3.0 java.lang.NoSuchMethodException

我很高兴听到android工作室已经做了一些更新,以便在android studio中简单地进行unit testing,所以我一直试图设置roboelectric但是我无法通过以下方法中出现的这个错误。 MainActivity = Robolectric.buildActivity(MainActivity.class).create().get(); 使用以下堆栈跟踪 引起:java.lang.RuntimeException:java.lang.NoSuchMethodException:java.lang.Object.attach(android.content.Context,android.app.ActivityThread,android.app.Instrumentation,android.os.IBinder,int,android .app.Application,android.content.Intent,android.content.pm.ActivityInfo,java.lang.CharSequence,android.app.Activity,java.lang.String,android.app.Activity $ NonConfigurationInstances,android.content.res .configuration)org.robolectric.util.ReflectionHelpers.traverseClassHierarchy(ReflectionHelpers.java:248)org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:138)… 36更多信息 为什么会发生这种情况以及我能做些什么才能超越它?

代码设计:性能与可维护性

语境化 我正在测试上下文中使用soot框架实现字节码指示器,我想知道哪个设计更好。 我正在为我正在检测的类中的每个方法构建TraceMethod对象,并且我想在多个类上运行此指令器。 哪个选项提供更高的性能(时空)? 选项1 :(地图) public class TraceMethod { boolean[] decisionNodeList; boolean[] targetList; Map<Integer,List> dependenciesMap; Map<Integer,List> decisionNodeBranchDistance; } 选项2 :(对象) public class TraceMethod { ArrayList targets = new ArrayList(); ArrayList decisionNodes = new ArrayList(); } public class DecisionNode { int id; Double branchDistance; boolean reached; } public class Target { int id; boolean reached; […]

玩! Framework 2.2.0:无法在Eclipse中进行调试

我正在尝试使用Eclipse(Kepler)在Play中调试我的unit testing! 项目。 我启动了play debug 。 在Eclipse中,我使用命令行输出提供的端口在Debug Configurations中创建了一个远程Java应用程序。 单击Apply,然后单击Debug,添加断点。 在我的Play项目的命令提示符中,我启动了测试 。 Eclipse永远不会在断点处停止。 这很烦人。 我使用的是Windows 7 Pro 64位。 谢谢你的帮助

CompletableFuture可用性和unit testing

我正在学习java 8 CompletableFuture并最终得到了这个。 所有的拳头,您如何看待这行代码? 我需要并行向不同的服务发送请求,然后等待所有服务响应并继续工作。 //service A CompletableFuture serviceAFuture = CompletableFuture.supplyAsync( () -> this.ServiceA.retrieve(serviceARequest), serviceAExecutorService ); //service B CompletableFuture serviceBFuture = CompletableFuture.supplyAsync( () -> this.ServiceB.retrieve(serviceBRequest), serviceBExecutorService ); CompletableFuture.allOf(serviceAFuture, serviceBFuture).join(); ServiceAResponse responseA = serviceAFuture.join(); ServiceBResponse responseB = serviceBFuture.join(); 甚至代码都在做我想要的,我在测试代码所在的类时遇到了问题。 我尝试使用Mockito并执行以下操作: doAnswer(invocation -> CompletableFuture.completedFuture(this.serviceAResponse)) .when(this.serviceAExecutorService) .execute(any()); 执行程序服务和服务响应在嘲笑,但测试永远不会结束,并且线程一直在等待这一行 CompletableFuture.allOf(serviceAFuture, serviceBFuture).join(); 我在这里缺少的任何暗示? 谢谢!

如何在真实条件下模拟Web应用程序的120个并发用户?

如何使用负载测试框架(如JMeter)模拟> 120个并发用户 ? 据我所知,如果我使用120个服务器或120个CPU核心,真正的并发是可能的。 您是如何/在真实条件下测试您的Web应用程序或服务的?

使用Powermock模拟类的构造函数时得到ExceptionInInitializerError。 怎么解决?

这是我的情况。 我有一个AbstractController类。 它有一个子类控制器。 在AbstractController的一个方法中,实例化了一个新的ApplicationLock。 我想在为Controller编写ut时模拟ApplicationLock。 我写了一个如下的测试用例。 @test public void testMethod(){ ApplicationLock mockLock=PowerMockito.mock(ApplicationLock.class); PowerMockito.when(mockLock.tryObtain()).thenReturn(true); PowerMockito.whenNew(ApplicationLock.class).withArguments(argThat(new IsFile()),anyString()).thenReturn(mockLock); } 我已经为测试类添加了必要的注释。 @RunWith(PowerMockRunner.class) @PrepareForTest({AbstractController.class}) 但是在运行此测试用例时出现以下错误。 这是AbstractController中的静态初始化程序。 引起:com.acompany.controller.common.AbstractController中的java.lang.NullPointerException。(AbstractController.java:65) private static final String DEFAULT_FOLDER = AbstractController.class.getProtectionDomain().getCodeSource() .getLocation().getPath(); 完整堆栈跟踪如下。 java.lang上的java.lang.Class.forName0(本机方法)中的java.lang.ExceptionInInitializerError,javassist中的javasslang.runtime.Desc.getClassObject(Desc.java:44)中的java.lang.Class.forName(Class.java:169)。 run.Desc.getClassType(Desc.java:153)at javassist.runtime.Desc.getType(Desc.java:123)at javassist.runtime.Desc.getType(Desc.java:79)at com.acompany.controller.portfolio .controllerTest.testIncrementalFail(ControllerTest.java:195)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java) :25)在org.powermock.modules.junit4.internal的org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)的java.lang.reflect.Method.invoke(Method.java:597)。 impl.PowerMockJUnit44RunnerDelegateImpl $ PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:307)at org.junit.internal.runners.MethodRoadie $ 2.run(Me thodRoadie.java:86)org.junit.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:94)at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl $ PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)在org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl $ PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:112)在org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl $ […]