使用Spring maven上下文,我想基于maven配置文件运行特定的测试.我想有一个标记测试组的简单方法.如果可能,我想使用注释.有哪些选项,如maven命令行参数,maven配置文件规范等.
说我有以下测试:
例:
// annotation("integration")
public class GeopointFormatterTest {
@Test
public void testIntegration1() { ... }
@Test
public void testIntegration2() { ... }
Run Code Online (Sandbox Code Playgroud)
当然,注释如@Profile(用于创建bean)和@ActiveProfile(用于选择创建bean的特定配置文件)不能用于选择测试.所有测试只针对以下语句运行:
mvn clean install -Pdevelopment
mvn clean install -Pdevelopment -Dspring.profiles.active = accepted
mvn clean install -Pdevelopment -Dspring.profiles.active = integration
正如所建议的那样,我也使用了@IfProfileValue.这是根据系统属性值选择测试的好方法.CustomProfileValueSource类可以推翻系统属性值,如:@ProfileValueSourceConfiguration(CustomProfileValueSource.class)
编辑和替代
下面的GREAT答案主要关注JUnit的@Category机制.谢谢大家!
一种不同的方法是通过以下步骤:[1]在maven配置文件中设置属性,[2]使用属性通过标准的surefire测试插件跳过测试.
[1]通过配置文件设置属性:
<profiles>
<profile>
<id>integrationtests</id>
<properties>
<integration.skip>false</integration.skip>
<acceptance.skip>true</acceptance.skip>
</properties>
</profile>
... other profiles
Run Code Online (Sandbox Code Playgroud)
[2]使用surefire测试插件中的属性跳过测试.
<build>
<plugins>
<plugin>
<!-- Run the integration test-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<skipTests>${acceptance.skip}</skipTests>
Run Code Online (Sandbox Code Playgroud)
从maven开始:mvn clean install -Pintegrationtests
在应用程序屏幕上,我有许多EditText视图.我的应用程序是使用Material Design(AppCompactActivity等)构建的.
在显示EditText字段时,长按我尝试在文本中选择多个单词.这允许我复制或共享该文本.选择多于1个单词似乎是不可能的.
自从迁移到Material Design后,我看到了两件事:
1 - 长按后,没有显示选择手柄.所以,在问号的位置,我预计逆水滴.这些是您通常用于更改特定选择的句柄.
问题:为什么这些反向滴眼液消失了?我在例如webview中选择文本时确实看到了它们.
是的,我使用'android:textIsSelectable ="true"'.下面是EditText布局.
2 - 所选文本的"共享"选项不可用.为什么?
什么是EditText字段?
<EditText
android:id="@+id/geocache_info_hint"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:singleLine="false"
android:lines="4"
android:scrollHorizontally="false"
android:scrollbars="vertical"
android:layout_marginLeft="5dp"
android:ellipsize="none"
android:textIsSelectable="true"
android:text=""/>
Run Code Online (Sandbox Code Playgroud)
在选择了一个文本(在这个例子中是1个单词)后,我也看到了一个额外的栏"tekstselectie"(= textselection)被放在屏幕上方.这也是自Android 4以来的一个区别.
**解决方案**
在我的主题中,我有一行导致不显示任何文本选择句柄的问题:
<item name="android:popupBackground">@color/window_background</item>
Run Code Online (Sandbox Code Playgroud)
@ color/window_background被选为白色.
Espresso用于自动测试我的应用程序.
编辑:下面你找到了许多答案!
如何在一长串自定义对象中的条目上单击(在自动Espresso测试脚本中)?
在Espresso文档中,有一个LongList示例.我通常使用对象列表.到目前为止,尝试从Map到Object的许多选项都没有产生好的结果.
Espresso文档说应该使用'onData'.所以,像:
onData( myObjectHasContent("my_item: 50")).perform(click());
onView(withId( R.id.selection_pos2)).check(matches(withText("50")));
Run Code Online (Sandbox Code Playgroud)
我的问题(我认为它们对学习社区有帮助): - 你能为此写一个好的匹配器吗? - 我们如何在'onData'中使用它?
现在是什么状况?在屏幕上,我有一个对象列表视图,如:
public class MyOjbect {
public String content;
public int size;
}
Run Code Online (Sandbox Code Playgroud)
我用来填充填充列表的适配器是:
public class MyObjectWithItemAndSizeAdapter extends ArrayAdapter<MyObjectWithItemAndSize> {
private final Context context;
private final List<MyObjectWithItemAndSize> values;
...
@Override
public View getView(int position, View concertView, ViewGroup parent) {
View view = null;
if (concertView != null) {
view = (LinearLayout) concertView;
} else {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate( R.layout.list_item, parent, false); …Run Code Online (Sandbox Code Playgroud) 是否有滚动到非列表的一般方法查看屏幕上尚未显示的项目?
没有任何预防措施,Espresso将指示"层次结构中没有视图与id匹配.....
我找到了这个答案......这是最好的方法吗?
onView( withId( R.id.button)).perform( scrollTo(), click());
Run Code Online (Sandbox Code Playgroud) 首先,我在 AWS 中创建了一个包含 Docker 映像的存储库。
然后我创建了一个任务定义和一个 ECS/EC2 集群。最后,我使用集群和任务定义创建了一个服务。工作正常。
如何在现有集群上重新部署更新的 Docker 镜像?
仅使用新(或现有)任务“更新”服务是行不通的。即使使用“强制新部署”选项也无效。
在Jenkins Docker容器中运行'npm install'时,我收到以下错误:
Run Code Online (Sandbox Code Playgroud)[INFO] --- exec-maven-plugin:1.6.0:exec (npm install) @ geosolutions --- npm WARN tar ENOENT: no such file or directory, open '/var/jenkins_home/workspace/aproject2/node_modules/.staging/schema-utils-bdceae78/package.json' npm WARN tar ENOENT: no such file or directory, open '/var/jenkins_home/workspace/aproject2/node_modules/.staging/schema-utils-bdceae78/README.md' ...(and many lines like) ... npm WARN tar ENOENT: no such file or directory, futime npm WARN tar ENOENT: no such file or directory, futime npm WARN tar ENOENT: no such file or directory, futime npm WARN tar ENOENT: no such file or directory, futime
没有生成'node_modules'.node_modules/.staging中只有少数几个.
进入Jenkins …
使用 Maven 构建 Spring-boot 映像时,我现在在 Dockerfile 中执行此操作。Maven 将下载所有依赖项,然后编译我的文件。这需要相当长的时间。
如何通过 docker-compose (Dockerfile) 指定构建过程重新使用我的“Windows10 Home”Maven 存储库?因此,(新)下载的数量很少。我的开发环境:我使用 Docker 快速入门终端,因此使用 docker-machine。
这是我的 docker-compose.yml 文件的一部分:
version: '3'
services:
spring-boot-app:
image: spring-boot-image
build:
context: ./
dockerfile: Dockerfile
depends_on:
- mysql-docker-container
ports:
- 8087:8080
volumes:
- $HOME/.m2/repository:/root/.m2/repository
- /data/spring-boot-app
Run Code Online (Sandbox Code Playgroud)
我的 Dockerfile 是:
FROM java:8
FROM maven:alpine
WORKDIR /app
COPY . /app
RUN mvn -v
RUN mvn clean install -DskipTests
EXPOSE 8080
LABEL maintainer=“xyz@holland.nl”
ADD ./target/spring-boot-example-0.0.1-SNAPSHOT.jar /developments/
ENTRYPOINT ["java","-jar","/developments/spring-boot-example-0.0.1-SNAPSHOT.jar"]
Run Code Online (Sandbox Code Playgroud) 有许多方法可以获得REST(简单)服务的良好安全性.我已经试过了.在这种情况下,只需要基本身份验证.所以,不是基于登录,RequestFilters等.请关注这个例子.
在为一个RestEasy'post'方法添加安全性的同时,我继续获得401个异常.如何安全访问"帖子"?我使用了Adam Bien /AtjemKönig的Authenticator代码.
如果没有web.xml中的安全设置,我将获得正常访问,因此部分代码工作正常.我不需要/想要任何登录屏幕.
Tomcat用户:conf/tomcat-users.xml:
<user username="wineuser" password="winepass" roles="winer"/>
Run Code Online (Sandbox Code Playgroud)
Web.xml文件:
<security-constraint>
<web-resource-collection>
<web-resource-name>wine secret</web-resource-name>
<url-pattern>/rest/wines/secret</url-pattern>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>winer</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
<security-role>
<role-name>winer</role-name>
</security-role>
Run Code Online (Sandbox Code Playgroud)
申请类:
@ApplicationPath("/rest")
public class RestEasyWineServices extends Application {
}
Run Code Online (Sandbox Code Playgroud)
Authenticator utils:
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.MultivaluedMap;
import javax.xml.bind.DatatypeConverter;
public class Authenticator implements ClientRequestFilter {
private final String user;
private final String password;
public Authenticator(String user, String password) {
this.user = user;
this.password = password;
} …Run Code Online (Sandbox Code Playgroud) 当无法在线访问互联网时,我希望(离线)HTML5应用程序通过OSM文件显示OSM地图.
您能举例说明我如何在离线Html5应用程序中显示OSM图块,这些图块是从Mapsforge/Geofabrik等离线OSM地图文件加载的吗?
示例:通过openstreetmap.org我首先导出了一小部分地图.如何在Html5离线webapp中显示此下载的OSM地图.
假设应用程序依赖于外部服务器http://otherserver.com上的REST 服务。为了进行测试,我想在 JUnit 环境中模拟外部休息调用(通过 Wiremock)。启动单独的服务器既耗时又不容易。使用 WiremockRule 看起来是正确的方向。创建模拟控制器并不是一种优雅的方式,因为可以使用 Wiremock。
例如 get(" http://otherserver.com/service3/ ");
PS:我当然知道我可以通过 Mockito 模拟 REST 调用。
使用 Wiremock 模拟 localhost 很容易。我如何使用该代码来模拟其他服务器和服务?我从流行的 Baeldung 示例中复制了部分内容。
public class WireMockDemo {
@Rule
public WireMockRule wireMockRule = new WireMockRule();
@Test
public void wireMockTestJunitOtherServer() {
try {
// **this does not work...**
configureFor("otherserver.com", 8080);
stubFor(get(urlPathMatching("/service2/.*"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("\"testing-library\": \"WireMock\"")));
// Test via simple client
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet request = new HttpGet("http://otherserver:8080/service2/test");
HttpResponse httpResponse = httpClient.execute(request); …Run Code Online (Sandbox Code Playgroud)