Tag: junit

如何模拟FileInputStream和其他* Streams

我有一个类,它获取GenericFile作为输入参数读取数据并进行一些额外的处理。 我需要测试它: public class RealCardParser { public static final Logger l = LoggerFactory.getLogger(RealCardParser.class); @Handler public ArrayList handle(GenericFile genericFile) throws IOException { ArrayList strings = new ArrayList(); FileInputStream fstream = new FileInputStream((File) genericFile.getFile()); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine = br.readLine();//skip header while ((strLine = br.readLine()) != null) { […]

Hibernate创建不需要的映射表

我正在创建一个架构。 我的架构如下 @Entity @Table(name = “PROMOTION”) public class Promotion { @Id @Column (name = “promotion_id”) private String promotionId; @JoinColumn(name = “seller_id”) private List sellerList; }; @Entity @Table(name = “SELLER”) public class Seller { @Id @Column (name = “seller_id”) private String sellerId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = “promotion_id”) private Promotion promotion; @ManyToMany(fetch = FetchType.LAZY) @JoinColumn(name = […]

Struts2 JUnit ActionContext对象

问题:测试期间Struts ActionContext为null 使用Struts2 JUnit插件我有以下测试: public class MainActionIT extends StrutsJUnit4TestCase { @Test public void testAction() { Map application = new HashMap(); application.put(“options”,”home”); ActionContext.getContext().put(“application”,application); ActionProxy proxy = getActionProxy(“/home”); String result = proxy.execute(); } } 两个相关的类如下: public class MainAction extends BaseAction { @Action(value = “/home”, results = {@Result(name = “success”, location = “home.jsp”)} public String getHome() { Map […]

JUnit:运行一个具有不同配置的测试

我有2种测试方法,我需要使用不同的配置运行它们 myTest() { ….. ….. } @Test myTest_c1() { setConf1(); myTest(); } @Test myTest_c2() { setConf2(); myTest(); } //—————— nextTest() { ….. ….. } @Test nextTest_c1() { setConf1(); nextTest(); } @Test nextTest_c2() { setConf2(); nextTest(); } 我不能从一个配置运行它们(如下面的代码),因为我需要单独的方法来执行tosca。 @Test tests_c1() { setConf1(); myTest() nextTest(); } 我不想写那两个方法来运行每个测试,我该如何解决这个问题? 首先我想写自定义注释 @Test @RunWithBothConf myTest() { …. } 但也许还有其他解决方案吗?

如何配置WireMock使用https(和随机端口)?

我试图设置wiremock在随机端口上运行https: @Rule public WireMockRule wireMockServer = new WireMockRule( WireMockConfiguration.wireMockConfig().dynamicPort().dynamicHttpsPort() ); 但是当我使用它并且我调用wireMockServer.httpsPort()我得到了exception: java.lang.IllegalStateException: Not listening on HTTPS port. Either HTTPS is not enabled or the WireMock server is stopped. at com.google.common.base.Preconditions.checkState(Preconditions.java:150) at com.github.tomakehurst.wiremock.WireMockServer.httpsPort(WireMockServer.java:184) 如何设置WireMock以使用https? 注意:我使用的是2.14.0版

JUnit测试失败作为ant目标执行

我正在尝试使用Cobertura插件为Jenkins获取代码覆盖,因此我在build.xml中运行测试然后覆盖报告,如下所示 Builds, tests, and runs the project CoberturaAndJenkins. 问题在于,当它试图运行unit testing时(我可以使用ant test运行),它一直在说 module-test: Running test cases… Running coberturaandjenkins.CoberturaAndJenkinsTest Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec Test coberturaandjenkins.CoberturaAndJenkinsTest FAILED 我已经更改,重新更改,重新更改build.xml几天没有任何运气。 我无法让它发挥作用。 拜托,我很感激这里的任何帮助。 这是我第一次使用ant(和Cobertura)

NoClassDefFoundError:注释处理期间的org / junit / AfterClass

我在使用maven进行注释处理期间使用CodeModel生成代码。 该代码用于JUnit测试: JMethod tearDownClass = testClass.method( JMod.PUBLIC | JMod.STATIC, Void.class, “tearDownClass”); tearDownClass._throws(Exception.class); tearDownClass.annotate(AfterClass.class); <- java.lang.NoClassDefFoundError 然而,编译过程在尝试检索java.lang.NoClassDefFoundError : org/junit/AfterClass时抛出了java.lang.NoClassDefFoundError : org/junit/AfterClass AfterClass.class ,这是一个注释本身。 对JUnit的依赖定义如下: junit junit 4.8.2 所以我的代码中应该有AfterClass.class 。 我该如何解决这个问题? 不清楚 调用codemodel的代码位于编译库中,其中junit不是“测试”依赖项。 但是,调用生成代码的代码具有相同的junit依赖性,但作为测试依赖性。 如果我将后一个依赖项更改为“not-a-test”依赖项,则问题就会消失。 为什么我必须将此依赖项定义为“not-a-test”,尽管只有调用codemodel的库明确使用它? 编辑 这是依赖树: net.dwst:codegentest:jar:1.0.0 +- junit:junit:jar:4.8.2:compile +- org.sonatype.maven.plugin:emma-maven-plugin:jar:1.2:test | +- emma:emma:jar:2.0.5312:test | \- org.apache.maven.reporting:maven-reporting-impl:jar:2.0.4:test | +- commons-validator:commons-validator:jar:1.2.0:test | | +- commons-beanutils:commons-beanutils:jar:1.7.0:test | […]

JUnit插件测试忽略Eclipse Neon中的目标平台

我有一些问题让JUnit插件测试使用Eclipse Neon M7工作,我真的很喜欢那些使用测试的人的输入(必须有人 ,对吧?)。 每当我开始在Eclipse Luna中运行的测试(但在Mars中没有 ,我认为是一个bug)并继续使用Tycho时我得到以下exception: !SESSION 2016-05-11 10:25:41.456 ———————————————– eclipse.buildId=unknown java.version=1.8.0_73 java.vendor=Oracle Corporation BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US Framework arguments: -version 3 -port 60297 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -classNames org.acme.test.test.core.ActivatorTest -application org.eclipse.pde.junit.runtime.uitestapplication -testApplication org.eclipse.ui.ide.workbench -testpluginname test.core Command-line arguments: -os win32 -ws win32 -arch x86 -consoleLog -version 3 -port 60297 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname […]

JUnit测试jdt.core Java模型

我正在尝试为我的代码进行一些JUnit测试。 但问题是,我使用了像DB2ompilationUnit,IPackageFragment,ITypes等Java模型。我没有得到如何创建一些ICompilationUnit然后测试。 我搜索谷歌和stackoverflow的信息,但没有找到的东西。 我的问题是,如何使用jdt.core的类进行Junit测试…有人可能会给我一些代码示例。 谢谢 这是我编码的方法: private void updateLists() { if(!getCompilationUnit().isEmpty()){ for(int i = 0; i < getCompilationUnit().size(); i++){ try { Document doc = new Document(getCompilationUnit().get(i).getSource()); int totalNumberOfCode = doc.getNumberOfLines(); IType type = getCompilationUnit().get(i).findPrimaryType(); IType[] types = getCompilationUnit().get(i).getTypes(); updateListPrimaryType(type, totalNumberOfCode, types); updateListIMethod(type); updateListMember(type,types); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } […]

使用InSequence批注时,arquillian UnsupportedOperationException

我在测试中添加@InSequence注释时出错: java.util.Collections上的java.lang.UnsupportedOperationException $ UnsetifiableList $ 1.set(Collections.java:1412)at java.util.Collections.sort(Collections.java:234)at org.jboss.arquillian.junit.Arquillian.getChildren (Arquillian.java:71)org.junit.runners.ParentRunner.getFilteredChildren(ParentRunner.java:426)org.junit.runners.ParentRunner.getDescription(ParentRunner.java:351)org.junit.runners.Suite。 describeChild(Suite.java:123)at com.intellij.junit4.IdeaSuite.describeChild(IdeaSuite.java:68)at com.intellij.junit4.IdeaSuite.getChildren(IdeaSuite.java:85)at org.junit.runners.ParentRunner .getFilteredChildren(ParentRunner.java:426)位于org.junit的org.junit.runners.ParentRunner.filter(ParentRunner.java:379)org.junit.runner.manipulation.Filter.apply(Filter.java:97)。 internal.requests.FilterRequest.getRunner(FilterRequest.java:37) 当我在没有这个注释的情况下运行测试时,一切正常。 知道什么是错的吗?