junit 相关问题

适用于Java和Scala的流行单元测试框架。最新版本JUnit 5支持丰富的基于注释和参数化的测试。考虑与Java或Scala标记一起使用以指示您的用例。

@RunWith(MockitoJUnitRunner::class) 无法识别mockito库

我试图使用 Mockito 来为我的测试提供上下文,但它说我需要添加我已经拥有的库“Gradle: org.mockito:mockito-core:4.0.0”。我在看...

回答 1 投票 0

将 androidx.datastore 实现 1.0.0 更新到 1.1.1 并且单元测试失败

我将 app/build.gradle 1.0.0 中的这些实现更新为 1.1.1 实现“androidx.datastore:数据存储首选项:$ androidXDatastore” 实现“androidx.datastore:

回答 1 投票 0

从 java 5 迁移到 java 6 后出现 SAXParseException

我在将应用程序从 Java 5 迁移到 java 6 时遇到问题。 这是一些在 Java5 上运行良好的单元测试。 单元测试的代码是: 公共空间

回答 1 投票 0

如何从 ArchUnit 的分层架构测试中排除基本 Java 功能?

我已经为我的干净架构编写了以下测试。我仍然有很多违规行为,例如 java.util 功能。我能否以某种方式将它们排除在 LayeredArchitecture ArchUnit 概念之外......

回答 1 投票 0

在 mvn 测试之后,由于某种原因我看到“测试运行:0”

我正在尝试使用“maven test”运行我的测试,但我总是收到测试运行:0,失败:0,错误:0,跳过:0 找不到问题所在。我猜问题出在 eather pom 或 runner 上 茹...

回答 1 投票 0

使用maven命令运行测试时不会触发Junit监听器

我遇到了以下问题,我有使用 JUNIT Testign 框架的放心 API 测试,我添加了一个 TestExecutionListener 来打印有关已执行测试的详细信息。 然而当...

回答 1 投票 0

如何将 jUnit 标签显示为 Surefire 报告的一部分?

我正在使用 jUnit 自动化我的测试用例,我想将其分类为一些特定的模块。现在,在运行测试用例后,我得到了可靠的报告。我想通过

回答 1 投票 0

有没有办法在生成的 html 报告中包含 JUnit 5 标签

我有一个中等大小的测试套件,其中包含带有各种标签的各种测试。例如: TestClassOne(标签:单元、api) TestClassTwo(标签:集成、api) ETC。 我查看了制作的...

回答 1 投票 0

无法在 VSCode 中运行 JUnit。 AssertEquals 符号无法识别

我在这里看到了之前的问题,解决了在 VSCode 上运行 junit 测试的问题,大多数解决方案建议将 JAR 添加到类路径中。然而,当我运行我的测试文件时,我有这个

回答 3 投票 0

kotlin Junit 的 pom.xml 文件失败,并显示“ClassSelector [className = 'InventoryTest'] 解析失败”

我正在尝试使用 JUnit 设置一些 kotlin 测试,但是当尝试运行测试时,出现以下错误: 发生内部错误。 org.junit.platform.commons.JUnitException:带有...的 TestEngine

回答 1 投票 0

单元测试用例 [Junit] 在原始 java servlet 中不可能实现

我有一个 Java servlet web 应用程序,我必须为此编写 junit 测试用例。 但是单元测试不起作用,因为没有使用模拟方法。

回答 1 投票 0

如何在集成测试中模拟 Amazon S3

我正在尝试为我的应用程序建立一个“行走的骨架”,它将使用 S3 来实现持久性。我想使用一个假的 S3 服务,这样每个开发人员的桌面都可以随意读/写。 我以为mocks3 wo...

回答 9 投票 0

在类路径中找不到功能:/cucumberOptions

我正在创建一个使用 cucumber、junit 和 TestNG 的自动化项目。 我的POM文件如下: 我正在创建一个使用 cucumber、junit 和 TestNG 的自动化项目。 我的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>main.project</groupId> <artifactId>project</artifactId> <version>0.0.1-SNAPSHOT</version> <name>project</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.3.0</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.5</version> </dependency> <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports --> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>5.0.5</version> </dependency> <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit</artifactId> <version>6.9.0</version> <scope>test</scope> </dependency> <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java --> <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>6.9.0</version> </dependency> <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-testng</artifactId> <version>6.9.0</version> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java8</artifactId> <version>6.8.1</version> <scope>test</scope> </dependency> </dependencies> <build> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> <configuration> <suiteXmlFiles> <suiteXmlFile>testng.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> <plugin> <artifactId>maven-site-plugin</artifactId> <version>3.7.1</version> </plugin> <plugin> <artifactId>maven-project-info-reports-plugin</artifactId> <version>3.0.0</version> </plugin> </plugins> </pluginManagement> </build> </project> 我还创建了一个新的 cucumberTestNG.xml 文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"> <suite name="Suite"> <listeners> <listener class-name = "project.Listeners"/> </listeners> <test name="Validate User Login"> <classes> <class name="cucumberOptions.TestRunner"/> </classes> </test> </suite> 我的测试运行者: package cucumberOptions; import org.junit.runner.RunWith; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; import io.cucumber.testng.AbstractTestNGCucumberTests; //@RunWith(Cucumber.class) @CucumberOptions( features = "src/test/java/features", glue = "stepDefinitions") public class TestRunner extends AbstractTestNGCucumberTests { } 如果我使用 TestNG Suite 运行 cucumberTestNG 文件,则会收到以下错误: Dec 09, 2020 9:16:16 PM io.cucumber.testng.TestNGCucumberOptionsProvider warnWhenJUnitCucumberOptionsAreUsed WARNING: Ignoring options provided by io.cucumber.junit.CucumberOptions on cucumberOptions.TestRunner. It is recommend to use separate runner classes for JUnit and TestNG. Dec 09, 2020 9:16:16 PM io.cucumber.core.runtime.FeaturePathFeatureSupplier get WARNING: No features found at classpath:/cucumberOptions 文件夹结构: 我的环境变量中有Java和Maven 我查看了诸如 cucumber jvm CucumberException: No features found at [] 之类的问题 并确保我的正确性用黄瓜进行测试(第一个答案),但没有运气。 如警告中所述 Dec 09, 2020 9:16:16 PM io.cucumber.testng.TestNGCucumberOptionsProvider warnWhenJUnitCucumberOptionsAreUsed WARNING: Ignoring options provided by io.cucumber.junit.CucumberOptions on cucumberOptions.TestRunner. It is recommend to use separate runner classes for JUnit and TestNG. 当前您正在导入 junit cucumber 选项。 import io.cucumber.junit.CucumberOptions; 对于 TestNg 运行器类,您需要导入 testng.CucumberOptions import io.cucumber.testng.CucumberOptions; cucumber-jvm 存储库中的示例 import io.cucumber.testng.AbstractTestNGCucumberTests; import io.cucumber.testng.CucumberOptions; import org.testng.annotations.DataProvider; @CucumberOptions(plugin = { "html:target/results.html", "message:target/results.ndjson" }) public class RunCucumberTest extends AbstractTestNGCucumberTests { @DataProvider(parallel = true) @Override public Object[][] scenarios() { return super.scenarios(); } } 我遇到了同样的问题,我通过将 Cucumber 依赖项从版本 6.11.0 降级到 1.2.6 解决了这个问题,并且我确保 cucumber-java 和 cucumber-testng 具有相同的版本,即 pom.xml 中的 1.2.6你可以看到下面: Aslo 我的 TestRunner 类如下所示,而不是扩展 AbstractTestNGCucumberTests 你应该(cucumber.api.testng.AbstractTestNGCucumberTests) 我也有类似的问题。原因是我有多个与 junit5 和 testng 相关的依赖项,所以我删除了所有与 junit5 相关的依赖项,只保留了 testng 的依赖项。然后,有了功能文件和 testng.xml 的正确路径,它就开始工作了。

回答 3 投票 0

如何使用 Android 依赖项和 robolectric 运行 Junit5 测试

我正在尝试运行这样的单元测试: @org.junit.jupiter.api.Test 无效junit5codeCoverage(){ 最终 int 结果 = new Foo().junit5(); Assert.assertEquals(Looper.getMain...

回答 3 投票 0

对包含 TransactionTemplate 的方法进行 Junit 单元测试

我有一个方法,其中包含 transactionTemplate 。我的测试在运行调试模式时有效,但在直接执行时无效。 当我运行调试模式时,我的测试有效,因为我认为事务操作...

回答 2 投票 0

Sping boot - 测试后删除数据库实体?

我正在寻找是否有一种方法可以使用某种注释而不是代码来在测试生成注册表后清理数据库。我找到了@Dirtiescontext,但似乎没有...

回答 1 投票 0

Junit 和 Mockito 如何使用模拟参数实例化模拟类

我对mockito不太熟悉。我试图模拟在另一个类中实例化的类的结果。 公共类测试类{ @测试 公共无效testSomething(){...

回答 1 投票 0

使用 TestRestTemplate 进行 Multipart POST 请求的集成测试返回 400

我知道类似的问题已经出现过几次,但遵循建议的修复方案并没有解决我的问题。 我有一个带有以下端点的简单控制器: @RequestMapping(...

回答 3 投票 0

单元测试使用 Mockito 单元测试 Servlet:模拟行为未执行

我在使用 Mockito 为 servlet 编写单元测试时遇到问题。我正在尝试使用 doAnswer 将测试值设置为 Value 来模拟业务对象 (BO) 对象的行为...

回答 1 投票 0

Mockito.mock() 不模拟 Java 17 中的类

StackOverflow 社区。 Mockito.mock() 在 Java 17 中无法按预期工作。当我将 java 版本升级到 Java 17 时,我可以使用 Java 8 模拟的类不会被模拟。 对此有什么想法吗?

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.