熟悉Play Framework并设置新的Web应用程序。
我想做一些模型单元测试但是当我运行play test
时,我收到以下错误消息:
[Opinions] $ test
[trace] Stack trace suppressed: run last *:testListeners for the full output.
[error] (*:testListeners) java.net.UnknownHostException: linux-hkem.site: linux-hkem.site: Der Name oder der Dienst ist nicht bekannt
[error] Total time: 10 s, completed 12.04.2014 21:42:35
Der Name oder der Dienst ist nicht bekannt
是德语,意思是:
The name or the service is not recognized
linux-hkem
是我的电脑名称。这似乎不是代码错误,而是配置错误。任何人都可以帮我解决这个问题吗?
下面是完整的堆栈跟踪:
java.net.UnknownHostException: linux-hkem.site: linux-hkem.site: Der Name oder der Dienst ist nicht bekannt
at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
at eu.henkelmann.sbt.JUnitXmlTestsListener.<init>(JUnitXmlTestListener.scala:25)
at play.Settings$$anonfun$defaultSettings$17.apply(PlaySettings.scala:94)
at play.Settings$$anonfun$defaultSettings$17.apply(PlaySettings.scala:94)
at scala.Function2$$anonfun$tupled$1.apply(Function2.scala:54)
at scala.Function2$$anonfun$tupled$1.apply(Function2.scala:53)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
at sbt.std.Transform$$anon$4.work(System.scala:64)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.Execute.work(Execute.scala:244)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.net.UnknownHostException: linux-hkem.site: Der Name oder der Dienst ist nicht bekannt
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
at java.net.InetAddress.getLocalHost(InetAddress.java:1469)
at eu.henkelmann.sbt.JUnitXmlTestsListener.<init>(JUnitXmlTestListener.scala:25)
at play.Settings$$anonfun$defaultSettings$17.apply(PlaySettings.scala:94)
at play.Settings$$anonfun$defaultSettings$17.apply(PlaySettings.scala:94)
at scala.Function2$$anonfun$tupled$1.apply(Function2.scala:54)
at scala.Function2$$anonfun$tupled$1.apply(Function2.scala:53)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
at sbt.std.Transform$$anon$4.work(System.scala:64)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
at sbt.Execute.work(Execute.scala:244)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
[error] (*:testListeners) java.net.UnknownHostException: linux-hkem.site: linux-hkem.site: Der Name oder der Dienst ist nicht bekannt
如果有人想知道的话, play run
的效果非常好。
我的build.sbt
name := "Opinions"
version := "1.0-SNAPSHOT"
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache
)
play.Project.playJavaSettings
那些应该运行的测试:
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
import com.fasterxml.jackson.databind.JsonNode; import org.junit。*;
import play.mvc。; import play.test。; import play.data.DynamicForm; import play.data.validation.ValidationError; import play.data.validation.Constraints.RequiredValidator; import play.i18n.Lang; import play.libs.F; import play.libs.F。*;
import static play.test.Helpers。; import static org.fest.assertions.Assertions。;
/**
*
* Simple (JUnit) tests that can call all parts of a play app.
* If you are interested in mocking a whole application, see the wiki for more details.
*
*/
public class ApplicationTest {
@Test
public void simpleCheck() {
int a = 1 + 1;
assertThat(a).isEqualTo(2);
}
@Test
public void renderTemplate() {
Content html = views.html.index.render("Your new application is ready.");
assertThat(contentType(html)).isEqualTo("text/html");
assertThat(contentAsString(html)).contains("Your new application is ready.");
}
}
...
import org.junit.*;
import play.mvc.*;
import play.test.*;
import play.libs.F.*;
import static play.test.Helpers.*;
import static org.fest.assertions.Assertions.*;
import static org.fluentlenium.core.filter.FilterConstructor.*;
public class IntegrationTest {
/**
* add your integration test here
* in this example we just check if the welcome page is being shown
*/
@Test
public void test() {
running(testServer(3333, fakeApplication(inMemoryDatabase())), HTMLUNIT, new Callback<TestBrowser>() {
public void invoke(TestBrowser browser) {
browser.goTo("http://localhost:3333");
assertThat(browser.pageSource()).contains("Your new application is ready.");
}
});
}
}
...
package Models;
import models.*;
import org.junit.*;
import static org.junit.Assert.*;
import play.test.WithApplication;
import static play.test.Helpers.*;
public class ModelsTest extends WithApplication {
/**
* Start Database for testing
*/
@Before
public void setUp() {
start( fakeApplication(inMemoryDatabase()) );
}
/**
* Create Test
*/
@Test
public void createAndRetrieveUser() {
new User("jakobabfalter@gmail.com", "Apfelmann", "xxxxxx");
User apfelmann = User.find.where().eq("email", "jakobxxxxxx@gmail.com").findUnique();
assertNotNull(apfelmann);
assertEquals("Apfelmann", apfelmann.getName());
}
}
答案 0 :(得分:2)
修正了这个编辑我的主机文件的问题:
echo "127.0.0.1 localhost linux-hkem.site" >> /etc/hosts
感谢:
Why does java.net.UnknownHostException require changes to the hosts file?