未找到 Wicket 单元测试 Translations.utils
Wicket unit testing Translations.utils not found
我最近开始在 wicket 中进行开发,想知道如何在单元测试本身中设置 wicket 应用程序。我目前正在使用 wicket 6.8 Core。
4.1.2 进行单元测试。
我想知道如何在应用程序上设置区域设置。
实际上也以一种很好的方式创建了测试应用程序。
我想要实现的是一个测试,看看是否可以返回一组从翻译文件加载的字符串。
//from the Class.
public Class Information(){
public Information(){}
public String getInfo(){
return TranslationUtil.getTranslation("RandomFieldNameTobeTranslated");
}
}
单元测试:
import org.junit.Before;
import org.junit.Test;
public class InformationTest(){
@Before
public void setup() throws Exception(){
//needs to be setup in someway it can be used by the test.
tester = new WicketTester();
WebApplication web = tester.getApplication();
web.usesDeploymentConfig();
web.configure();
web.initApplication();
Session.get().setLocale(new Locale("en_us"));
}
@Test
public test(){
Information information = new Information();
assertEquals("Foo is Foo", "Foo", information.getInfo() );
}
}
单元测试将运行代码并得到一个无法找到属性。
这只是一个基本测试,描述了问题。
java.util.MissingResourceException:
Unable to find property: 'RandomFieldNameTobeTranslated'. Locale: null, style: null
尝试了一些初始化和配置的变体。但是我太缺乏经验,不知道如何以正确的方式初始化 wicket 以进行开发单元测试。
问题:
如何初始化 wicket 以便它可以在会话中找到语言环境?
如何将 wicket 重定向到正确的翻译文件?
生产版本有效,但我想构建一个单元测试,它似乎需要 'application'。它可以被嘲笑,但作为最后的手段,因为它用于分配位置,我宁愿测试 'value equals value'.
来自#wicket 的@selckin:
只需通过以下方式启动它:
new WicketTester(new YourApplicationClas());
之后的实际单元测试代码:
import org.junit.Before;
import org.junit.Test;
import java.util.Locale;
public class SchedulerModelTest {
@Before
public void setup() throws Exception {
new WicketTester(new ReconAdminApplication());
Session.get().setLocale(new Locale("en_us")); //always set the locale.
}
@Test
public test(){
Information information = new Information();
assertEquals("Foo is Foo", "Foo", information.getInfo() );
}
}
我最近开始在 wicket 中进行开发,想知道如何在单元测试本身中设置 wicket 应用程序。我目前正在使用 wicket 6.8 Core。 4.1.2 进行单元测试。
我想知道如何在应用程序上设置区域设置。 实际上也以一种很好的方式创建了测试应用程序。 我想要实现的是一个测试,看看是否可以返回一组从翻译文件加载的字符串。
//from the Class.
public Class Information(){
public Information(){}
public String getInfo(){
return TranslationUtil.getTranslation("RandomFieldNameTobeTranslated");
}
}
单元测试:
import org.junit.Before;
import org.junit.Test;
public class InformationTest(){
@Before
public void setup() throws Exception(){
//needs to be setup in someway it can be used by the test.
tester = new WicketTester();
WebApplication web = tester.getApplication();
web.usesDeploymentConfig();
web.configure();
web.initApplication();
Session.get().setLocale(new Locale("en_us"));
}
@Test
public test(){
Information information = new Information();
assertEquals("Foo is Foo", "Foo", information.getInfo() );
}
}
单元测试将运行代码并得到一个无法找到属性。 这只是一个基本测试,描述了问题。
java.util.MissingResourceException:
Unable to find property: 'RandomFieldNameTobeTranslated'. Locale: null, style: null
尝试了一些初始化和配置的变体。但是我太缺乏经验,不知道如何以正确的方式初始化 wicket 以进行开发单元测试。
问题:
如何初始化 wicket 以便它可以在会话中找到语言环境?
如何将 wicket 重定向到正确的翻译文件?
生产版本有效,但我想构建一个单元测试,它似乎需要 'application'。它可以被嘲笑,但作为最后的手段,因为它用于分配位置,我宁愿测试 'value equals value'.
来自#wicket 的@selckin: 只需通过以下方式启动它:
new WicketTester(new YourApplicationClas());
之后的实际单元测试代码:
import org.junit.Before;
import org.junit.Test;
import java.util.Locale;
public class SchedulerModelTest {
@Before
public void setup() throws Exception {
new WicketTester(new ReconAdminApplication());
Session.get().setLocale(new Locale("en_us")); //always set the locale.
}
@Test
public test(){
Information information = new Information();
assertEquals("Foo is Foo", "Foo", information.getInfo() );
}
}