草庐IT

java - 匿名类作为泛型参数

我想创建一个类,从匿名类定义中获取一个对象来存储。我使用通用类型类来实现这一点。然后我想使用函数接口(interface)定义一些操作,将此对象作为参数进行处理。代码胜于Eloquent。所以看看这个:publicclassTest{@FunctionalInterfacepublicinterfaceoperation{voidexecute(Tobject);}privateTobj;publicTest(T_obj){obj=_obj;}publicvoidrunOperation(operationop){op.execute(obj);}publicstaticvoidmai

java - 在Java中将静态方法作为参数传递

您好,我正在测试具有一些验证方法的类,我一直在想是否有办法减少重复代码。@TestvoidtestCorrectEmailValidator(){ListcorrectEmails=Arrays.asList("test@test.com","test123@test123.com","test@test.com.in","test.test2@test.com","test.test2.test3@test.com","TEST.2test@test.com");for(Stringemail:correctEmails){booleanisValid=UserCredentials

java - Maven 和代码指标 : check for existence of a test case for each class

在Maven中是否可以使用某些东西来自动执行这种检查?我看到了checkstyle和PMD,但没有找到此功能。基本上,如果有类A而没有ATestCase,我希望构建失败。我知道,这不是一个严格的检查,可以通过只创建类轻松绕过,但目前这就足够了。 最佳答案 你在找什么正如JensPiegsa指出的那样,您正在寻找的是一种可以显示测试覆盖率的工具,换句话说,就是您测试使用的代码百分比。它允许您以比(至少按类测试)更可靠的方式查看您的代码测试了多少。您可以使用Cobertura,它很好地集成在Maven中:http://mojo.code

java - 与 TestNG 并行的参数化 Selenium 测试

首先,对不起我的英语,它不是那么完美:)所以我面临以下问题:我正在尝试使用SeleniumGrid和TestNg在不同的浏览器中运行并行测试,并在@BeforeTest方法中传递参数。我的问题是,当每个测试都被初始化时,它们似乎会使用最后一个测试的参数。所以在这个例子中,当我运行测试时,它会打开两个Chrome,而不是一个Firefox和一个Chrome。(browser.getDriver()方法返回一个RemoteWebDriver)TestNG.xml:AbstractTest类:publicclassSeleniumTest{privatestaticListwebDriver

java - 什么时候加载类?

嗯,我有这样一段代码:publicclassMain{publicstaticvoidmain(String[]args){Testt;//1Integeri=newInteger(1);//2t=newTest();//3System.out.println(Test4.a);//4}}classTest{privateinta=10;privateTest2t2;//5Listlist=newArrayList(){{for(inti=0;i我不知道如何(全部或部分)以及何时加载类。所以:Testt;-它不是一个活跃的用法,但引用t必须是一个明确的类型。测试类是否已加载(可能是部分

java测试: accelerate time to test timeouts?

我有一个管理游戏回合的应用程序,它相当复杂,并且有很多计时器会产生超时。由于它们经常互操作,因此很难确保一切正常(并保持正常工作)。我想测试它,但某些超时是几分钟,要完全测试它至少需要一个小时!!有没有办法为计时器伪造加速时间?或者我应该按比例减少所有超时,测试它们,然后每次都再次增加?谢谢! 最佳答案 实现此目的的一种方法是制作您自己的界面,为Timer提供一个精简的包装器。然后,您可以在代码中的任何地方针对接口(interface)进行编程。之后,您对接口(interface)进行了两次实现。第一个是连接到真实Timer对象的预

java - 如何在 JUnit 4.x 中创建嵌套的测试套件?

我正在尝试将JUnit添加到一个大型项目中,但在嵌套测试套件时遇到了困难。例如:@RunWith(Suite.class)@Suite.SuiteClasses({Test2.class,.....})publicclassTest1{}@RunWith(Suite.class)@Suite.SuiteClasses({Test3.class,.....})publicclassTest2{//mighthavetests}@RunWith(Suite.class)publicclassTest3{//testshere}每个类在它自己的包以及所有子包TestSuites中运行测试运行

java - Gradle:如何列出所有 "given tests"

我试试下面的代码:roroco@roroco~/Dropbox/jvs/ro-idea$gradletest--tests"ro.idea.ToggleTest.testIsAd":ro:compileJavaUP-TO-DATE:ro:processResourcesUP-TO-DATE:ro:classesUP-TO-DATE:ro:jar:compileJava:processResourcesUP-TO-DATE:classes:compileTestJava:processTestResourcesUP-TO-DATE:testClasses:test:ro:compileT

java - 当我使用命令 `mvn test -Xlint:unchecked` 时。出现一些错误

[ERROR]Nopluginfoundforprefix'lint'inthecurrentprojectandintheplugingroups[org.apache.maven.plugins,org.codehaus.mojo]availablefromtherepositories[local(C:\Users\Administrator\.m2\repository),alimaven(http://maven.aliyun.com/nexus/content/groups/public/)]->[Help1]org.apache.maven.plugin.prefix.N

java - hibernate restrictions.in with and,怎么用?

我有如下表格id,employee_no,survey_no,name1test1test_name2test21test_name23test31test_name34test42test_name4如何通过将下面的AND组合成一个IN语句来使用Restriction.in进行查询?IN[(if(survey_no==1)&&employee_no=='test'),(if(survey_no==1)&&employee_no=='test2'),...] 最佳答案 我认为这是您要使用的条件组合(顺便说一句。帮助Hibernate