小编Car*_*don的帖子

Java:如何将环境变量添加到 Gradle 中的 JUnit 测试

我已经设法让测试任务来运行我的单元测试,但它们失败了,因为我使用的 env 属性没有设置,例如: String base=System.getenv("TESTNG_BASE_PATH");

所以,我做了类似的事情:

tasks.withType(Test) {
   systemProperty 'TESTNG_BASE_PATH','long\\path\\to\env\var\value'   
}
Run Code Online (Sandbox Code Playgroud)

但是我仍然从我的代码中得到相同的异常,即找不到文件,所以这显然不是正确的方法。

那请问怎么做呢?

gradle

7
推荐指数
1
解决办法
5008
查看次数

Spring Boot单元测试未检测到自动接线组件的模块

我们将基于Maven的Spring Boot项目分为以下两个模块:

ProjectRoot
-SharedModel
-Application
--main
---java
----com....(Application.java)
-----com....(ClassToAutowire.java)
--test
----com....(ApplicationTest.java)
-----com....(ClassToAutowireTest.java)
Run Code Online (Sandbox Code Playgroud)

测试类如下所示:

@RunWith(SpringRunner.class)
public class ClassToAutowireTest extends BaseTest {

    @Autowired
    private ClassToAutowire classToAutowire;

    @Before
    public void setup() throws IOException {        
    ....
    }

    @Test
    public void someTest() {
        ....
        assertEquals(this.classToAutowire.isSupported(this.message), true);
    }

}
Run Code Online (Sandbox Code Playgroud)

ClassToAutowire如下所示:

@Component
public class ClassToAutowire {

    private ConfigurationService configurationService;

    @Autowired
    public ClassToAutowire(ConfigurationService configurationService) {
        this.configurationService = configurationService;
    }



    ....

}
Run Code Online (Sandbox Code Playgroud)

Application.java如下所示:

@SpringBootApplication
@EnableRetry
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
} …
Run Code Online (Sandbox Code Playgroud)

java intellij-idea spring-boot spring-boot-test

6
推荐指数
1
解决办法
9200
查看次数

SpringBoot 中的单元测试 Freemarker 模板 - 无法初始化 freemarker 配置

我们正在使用 Freemarker 为我们的应用程序将要发送的电子邮件生成 HTML 代码。

我们的使用和配置基于https://github.com/hdineth/SpringBoot-freemaker-email-send 特别是:

package com.example.techmagister.sendingemail.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;
import org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean;

import java.io.IOException;

@Configuration
public class FreemarkerConfig {

    @Bean(name="emailConfigBean")
    public FreeMarkerConfigurationFactoryBean getFreeMarkerConfiguration(ResourceLoader resourceLoader) {
        FreeMarkerConfigurationFactoryBean bean = new FreeMarkerConfigurationFactoryBean();
        bean.setTemplateLoaderPath("classpath:/templates/");
        return bean;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,在任何地方都没有关于如何使用 JUnit 5 为此运行单元测试的信息或文档。

当我添加相关依赖项时

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

版本:

        <junit.jupiter.version>5.3.1</junit.jupiter.version>
        <mockito.version>2.23.0</mockito.version>
Run Code Online (Sandbox Code Playgroud)

并做了一个测试类: …

junit freemarker spring-boot junit5

6
推荐指数
1
解决办法
1751
查看次数

从Unix迁移到Linux时,Makefile包含指令

我的任务是迁移一个古老的基于C++的代码,从Unix环境到Linux.该项目由多个Makefile组成,用于库的不同"模块".我已经解决了一些问题,但现在遇到了include指令的问题.

显然,Makefiles的构造方式是为不同的文件提供单独的 include指令,并且它在Unix服务器中工作了多年.

例如:

include ../../../../util/genmake.def

processControl.slOBJS = processControl.o
outputControlOBJS = outputControl.o
inputControlOBJS = inputControl.o
cleanList  = *.o *.C *.out processControl.sl outputControl inputControl

all: processControl.sl  outputControl inputControl

processControl.sl: $(processControl.slOBJS)
        include ../../../../util/genmake.slinc

outputControl: $(outputControlOBJS)
        include ../../../../util/genmake.exeinc

inputControl: $(inputControlOBJS)
        include ../../../../util/genmake.exeinc

include ../../../../util/genmake.inc
Run Code Online (Sandbox Code Playgroud)

你可以在这里看到,tabbed包含,只能引用指定的目标!它们是该目标的配方的一部分.

但是,这个构造在Linux中不起作用,我收到此错误:

include ../../../../util/genmake.slinc
make: include: Command not found
make: *** [processControl.sl] Error 127
Run Code Online (Sandbox Code Playgroud)

显然,我不能只删除标签,因为包含应仅适用于该目标...

所以,我试图用shell'source'命令替换它来源包含的文件,如:

        source ../../../../util/genmake.slinc
Run Code Online (Sandbox Code Playgroud)

这显然不起作用,我也尝试将包含的代码直接引入include文件(注释掉include命令) - 这会处理与Makefile相关的错误,但这不是一个好的解决方案,因为它真的很难迁移和维护它,不得不将整个项目中的相同代码复制到所有模块中,然后当然每一个微小的变化都要反映在所有文件上.

任何Make专家可以就此问题提出建议吗?此外,一般来说,欢迎任何有关如何最好地处理此迁移任务的建议:)

谢谢!

编辑 - 额外信息:genmake.slinc的内容:


#######################################################################
## This include will inherit the target and dependent files in …
Run Code Online (Sandbox Code Playgroud)

c++ makefile gnu-make

5
推荐指数
1
解决办法
286
查看次数

如何使用Jackson动态地将键值的JSON数组映射到子对象?

假设我们有一个如下所示的JSON结构:

{
 "field1": "val1",
 "field2": "v2",
 "f3": "v3",
 "f4": "v4",
 "arrayOfStuff": [
  {
   "f5": "v5",
   ....
   "f10": "v10"
  }
 ],
 "attributes": [
  {"att1": "att1"},
  {"att2": "attr2"},
  {"att3": "att3"}
 ],
 "options": [
  "ignoreMismatchFile"
 ]
}
Run Code Online (Sandbox Code Playgroud)

我们匹配的java类看起来像:

public class Message {
   @IsUniqueId
   private String field1; //
   private String field2;
   private String field3;
   private String field4;
   private List<AnotherObject> f5;
   @JsonProperty("attributes")
   private LinkedHashMap<String, String> attributes;
   private List<String> options;
   ....
}
Run Code Online (Sandbox Code Playgroud)

解析代码如下所示:

protected Message loadSavedMessageAsMessageObject(String path) throws IOException {
    File file = ResourceUtils.getFile(path);
    if (file.exists()) …
Run Code Online (Sandbox Code Playgroud)

java json jackson spring-boot jackson2

5
推荐指数
1
解决办法
733
查看次数

打印mySQL数据库的ER图(800多个表)

我们有一个由Parallels构建的系统,它依赖于一个巨大的(800+)表来维护一切.

我需要学习这个系统,以便能够编写查询来检索数据,以便根据各种需求生成报告.

我很明显,难以隔离哪些表当前与手头的任务相关,所以我认为最好的方法是,在多个页面上生成和打印ERD,用于整个表系统.

我试图使用TOAD拖动所有表 - 崩溃了:)在第二次尝试时,我拖动表AN,在(长)之后,MZ表成功.

我甚至设法将它们全部调整大小,安排并将ERD保存到文件中.

但是,当我进入打印或预览时,打印的子过程会崩溃.

关于如何打印这个庞大的ERD的任何建议?或许是另一种方法?表名似乎不太自我解释,所以我不能(而且老实说,并不是真的想要)超过800多个表,并希望我不会错过我需要的,或部分.

在我真正编写脚本和代码之前,我将非常感谢有关如何继续的任何建议或想法.

数据库在CentOS下的mySQL上,有些表是InnoDB,有些是MyISAM.许多表似乎都有外键.

谢谢!

mysql sql database erd

3
推荐指数
2
解决办法
5941
查看次数

InDelta和InEpsilon之间的区别

从文档:

https://godoc.org/github.com/stretchr/testify/assert#InDelta

InDelta断言这两个数字彼此相差不大

https://godoc.org/github.com/stretchr/testify/assert#InEpsilon

InEpsilon断言预期和实际的相对误差小于epsilon

他们的代码在目的上似乎是相同的:

func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {

    af, aok := toFloat(expected)
    bf, bok := toFloat(actual)

    if !aok || !bok {
        return Fail(t, fmt.Sprintf("Parameters must be numerical"), msgAndArgs...)
    }

    if math.IsNaN(af) {
        return Fail(t, fmt.Sprintf("Expected must not be NaN"), msgAndArgs...)
    }

    if math.IsNaN(bf) {
        return Fail(t, fmt.Sprintf("Expected %v with delta %v, but was NaN", expected, delta), msgAndArgs...)
    }

    dt := af - bf
    if dt < -delta || dt > …
Run Code Online (Sandbox Code Playgroud)

go testify

3
推荐指数
1
解决办法
360
查看次数

删除 IntelliJ IDEA 中的包装函数?

我有一个包含多个语句的 foreach 块,例如:

$outputArr[$type . "_" . "orgName"] = urlencode($this->params[$prefix."companyname"]);

在这个例子中,是否有任何方便的快捷方式可以删除 urlencode 包装器,而无需我手动转到行尾,删除结束括号?

奖励点:用一个命令urlencode对块中所有相同的重复换行线执行此操作:)

intellij-idea

1
推荐指数
1
解决办法
642
查看次数

Java Junit4 支持扩展基类

一个问题:

当我做类似的事情时:

package path.to.common.package.test;
@BeforeClass
public class CommonTestSetup {

  public void setUp() {
   // Setup Stiff
  }
}
Run Code Online (Sandbox Code Playgroud)

和同一个包中的另一个类设置:

package path.to.common.package.test;
public class TestTest extends CommonTestSetup {
    @Test
    public void testGetTestReturnsCorrectStrings() {
    // do asserts etc
    }
}
Run Code Online (Sandbox Code Playgroud)

然后对testGetTestReturnsCorrectStrings我执行 JUnit 测试时出现错误:

org.junit.runners.model.InvalidTestClassError: Invalid test class 'org.junit.runner.manipulation.Filter':
  1. No runnable methods
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:456)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:99)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:84)
    at org.junit.runners.JUnit4.<init>(JUnit4.java:23)
    at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:66)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:66)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:39)
    at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:80)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:71)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:523) …
Run Code Online (Sandbox Code Playgroud)

java junit junit4

1
推荐指数
2
解决办法
8645
查看次数

找不到测试-在裸骨Spring Boot Maven项目上运行jUnit 5测试用例时,测试套件为空

所以我们得到了信息

Process finished with exit code 0
Empty test suite.
Run Code Online (Sandbox Code Playgroud)

当尝试在我们的多模块项目上运行Junit5测试用例时,为了测试问题的根源,我决定从头开始尝试一个新项目(我正在使用IntelliJ IDEA 2018.2.4)。

以下简单项目POM文件出现相同问题:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.org.bu.dep.app</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.0.5.RELEASE</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.vaadin.external.google</groupId>
                    <artifactId>android-json</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.3.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>5.3.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins> …
Run Code Online (Sandbox Code Playgroud)

java maven spring-boot junit5

0
推荐指数
5
解决办法
3432
查看次数