我正在使用Mockito 1.9.0.我想在JUnit测试中模拟一个类的单个方法的行为,所以我有
final MyClass myClassSpy = Mockito.spy(myInstance);
Mockito.when(myClassSpy.method1()).thenReturn(myResults);
Run Code Online (Sandbox Code Playgroud)
问题是,在第二行,myClassSpy.method1()实际上是被调用,导致异常.我使用模拟的唯一原因是,以后,无论什么时候myClassSpy.method1()被调用,都不会调用真正的方法并myResults返回对象.
MyClass是一个接口myInstance,如果重要的话就是它的实现.
我需要做些什么来纠正这种间谍行为?
当我尝试推动我提交的更改时,我收到以下错误...
git.exe push -v --progress "origin" iteration1:iteration1
remote: *********************************************************************
To ssh://git@mycogit/cit_pplus.git
! [remote rejected] iteration1 -> iteration1 (pre-receive hook declined)
error: failed to push some refs to 'ssh://git@mycogit/cit_pplus.git'
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
我在Mac 10.7.5,SVN 1.7和Eclipse Subversive插件上使用Eclipse Juno.Occassioanlly,当我尝试从项目中提交更改时(通过右键单击包浏览器中的项目,选择"Team" - >"Commit"),我收到错误:
Some of selected resources were not committed.
Some of selected resources were not committed.
svn: E200007: Commit failed (details follow):
svn: E200007: Commit failed (details follow):
svn: E200007: CHECKOUT can only be performed on a version resource [at this time].
svn: E175002: CHECKOUT request failed on '/svn/subco-digital.coderepo/!svn/rvr/2110/trunk/myproject/src/main/java/org/mainco/subco/myproject/validator/UserFormValidator.java'
Run Code Online (Sandbox Code Playgroud)
我已经确认我已经检查了我项目的最新版本.我该如何处理这些重复的错误?
我正在使用Spring 3.1.4.RELEASE和Mockito 1.9.5.在我的Spring课程中,我有:
@Value("#{myProps['default.url']}")
private String defaultUrl;
@Value("#{myProps['default.password']}")
private String defaultrPassword;
// ...
Run Code Online (Sandbox Code Playgroud)
从我目前设置的JUnit测试开始,如下所示:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:test-context.xml" })
public class MyTest
{
Run Code Online (Sandbox Code Playgroud)
我想为我的"defaultUrl"字段模拟一个值.请注意,我不想模拟其他字段的值 - 我想保留它们的原样,只保留"defaultUrl"字段.另请注意,setDefaultUrl我的课程中没有明确的"setter"方法(例如),我不想仅仅为了测试而创建任何方法.
鉴于此,我如何模拟该字段的值?
我在最新版本的Jenkins和Maven Release插件上使用SVN,Maven 3.0.3.我正在尝试使用Maven发布插件(通过Jenkins)进行干运行,因此执行选项...
Executing Maven: -B -f /scratch/jenkins/workspace/myproject/myproject/pom.xml -DdevelopmentVersion=53.0.0-SNAPSHOT -DreleaseVersion=52.0.0 -Dusername=***** -Dpassword=********* -DskipTests -P prod -Dresume=false -DdryRun=true release:prepare
Run Code Online (Sandbox Code Playgroud)
但干运行正在消失,错误如下......
[JENKINS] Archiving /scratch/jenkins/workspace/myproject/myproject/pom.xml to /home/evotext/hudson_home/jobs/myproject/modules/org.mainco.subco$myproject/builds/2013-11-18_16-09-14/archive/org.mainco.subco/myproject/52.0.0/myproject-52.0.0.pom
Waiting for Jenkins to finish collecting data
mavenExecutionResult exceptions not empty
message : Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.0:prepare (default-cli) on project myproject: You don't have a SNAPSHOT project in the reactor projects list.
cause : You don't have a SNAPSHOT project in the reactor projects list.
Stack trace :
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.0:prepare (default-cli) …Run Code Online (Sandbox Code Playgroud) 我正在使用Maven 3.0.3,JUnit 4.8.1和Jacoco 0.6.3.201306030806,我正在尝试创建测试覆盖率报告.
我有一个只有单元测试的项目,但我无法运行报告,我反复收到错误:Skipping JaCoCo execution due to missing execution data file当我运行时:
mvn clean install -P test-coverage
Run Code Online (Sandbox Code Playgroud)
这是我的pom配置方式:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx2048m</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<reuseForks>true</reuseForks>
<argLine>-Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
...
<profile>
<id>test-coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.3.201306030806</version>
<configuration>
<destfile>${basedir}/target/coverage-reports/jacoco-unit.exec</destfile>
<datafile>${basedir}/target/coverage-reports/jacoco-unit.exec</datafile>
</configuration>
<executions>
<execution>
<id>prepare-unit-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- prepare agent for measuring integration tests -->
<execution>
<id>prepare-integration-tests</id>
<goals> …Run Code Online (Sandbox Code Playgroud) 我想将org.w3c.dom.Document对象转换为String.我正在使用Java 6,并且愿意使用任何(完全免费的)技术来完成任务.我尝试了这个线程的解决方案 - 是否有一种更优雅的方式将XML文档转换为Java中的String而不是此代码?,他们在哪里
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
String html = lsSerializer.writeToString(doc);
Run Code Online (Sandbox Code Playgroud)
但受到以下可怕的例外的欢迎......
org.w3c.dom.DOMException: DOM method not supported
at org.w3c.tidy.DOMDocumentImpl.getImplementation(DOMDocumentImpl.java:129)
at com.myco.myproj.cleaners.JTidyCleaner.outputDocAsString(JTidyCleaner.java:74)
at com.myco.myproj.cleaners.JTidyCleaner.parse(JTidyCleaner.java:63)
at com.myco.myproj.util.NetUtilities.getUrlAsDocument(NetUtilities.java:51)
at com.myco.myproj.parsers.AbstractHTMLParser.getEventFromElement(AbstractHTMLParser.java:131)
at com.myco.myproj.parsers.AbstractHTMLParser.parsePage(AbstractHTMLParser.java:100)
at com.myco.myproj.parsers.AbstractHTMLParser.getEvents(AbstractHTMLParser.java:63)
at com.myco.myproj.domain.EventFeed.refresh(EventFeed.java:87)
at com.myco.myproj.domain.EventFeed.getEvents(EventFeed.java:72)
at com.myco.myproj.parsers.impl.ChicagoCouncilGlobalAffairsParserTest.testParser(ChicagoCouncilGlobalAffairsParserTest.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at …Run Code Online (Sandbox Code Playgroud) 我在Mac Yosemite上使用Maven 3.3.3和Java 8.我有一个多模块项目.
<modules>
<module>first-module</module>
<module>my-module</module>
…
</modules>
Run Code Online (Sandbox Code Playgroud)
当我构建我的一个子模块,例如,上面的"my-module",使用"mvn clean install"时,构建尝试从我在〜/ .m2中定义的远程存储库下载子模块工件. /settings.xml文件.输出低于
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-module 87.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloaded: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml (788 B at 0.9 KB/sec)
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first-module-87.0.0-20151104.200545-4.pom
Run Code Online (Sandbox Code Playgroud)
在尝试从远程存储库下载之前,如何强制Maven先检查我的本地〜/ .m2/repository?下面是我在〜/ .m2/settings.xml文件中定义远程存储库的地方......
<profile>
<id>releases</id>
<activation>
<property>
<name>!releases.off</name>
</property>
</activation>
<repositories>
<repository>
<id>releases</id>
<url>https://my.remoterepository.com/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>snapshots</id>
<activation>
<property>
<name>!snapshots.off</name>
</property>
</activation>
<repositories>
<repository>
<id>snapshots</id>
<url>https://my.remoterepository.com/nexus/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
Run Code Online (Sandbox Code Playgroud)
编辑: …
我在Mac 10.7.4上使用Eclipse Indigo.工作时,我会得到这些定期的,烦人的对话框
'Periodic workspace save.' has encountered a problem.
Could not write metadata for '/.org.eclipse.jdt.core.external.folders'.
/Users/davea/Dropbox/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.jdt.core.external.folders/.markers.snap (No such file or directory)
Run Code Online (Sandbox Code Playgroud)
我似乎能够像往常一样继续,但我想知道如何消除这些错误.
我在Linux上使用bash shell.我有这个简单的脚本......
#!/bin/bash
TEMP=`sed -n '/'"Starting deployment of"'/,/'"Failed to start context"'/p' "/usr/java/jboss/standalone/log/server.log" | tac | awk '/'"Starting deployment of"'/ {print;exit} 1' | tac`
echo $TEMP
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此脚本时
./temp.sh
Run Code Online (Sandbox Code Playgroud)
所有输出都打印出来没有回车/换行.不知道我将输出存储到$ TEMP的方式,还是echo命令本身.
如何将命令的输出存储到变量并保留换行符/回车符?