junit

Is there a way to run MySQL in-memory for JUnit test cases?

匆匆过客 提交于 2019-12-17 15:20:11
问题 I'm just trying to add test cases for services accessing a MySQL DB, and I would like to recreate the whole schema (and for some scenarios also just use a MySQL dump file with the data needed for each test case). I was looking around and found some guys using SQLite / H2 and others to do this, but I'm just wandering if there is any way to run MySQL in-memory so I don't need to worry about anything specific to the the MySQL dialect I might be using on our services. 回答1: The easiest way for

Separation of JUnit classes into special test package?

岁酱吖の 提交于 2019-12-17 15:05:26
问题 I am learning the concepts of Test-Driven Development through reading the Craftsman articles (click Craftsman under By Topic ) recommended in an answer to my previous question, "Sample project for learning JUnit and proper software engineering". I love it so far! But now I want to sit down and try it myself. I have a question that I hope will need only a simple answer. How do you organize your JUnit test classes and your actual code? I'm talking mainly about the package structure, but any

python接口自动化(二十一)--unittest简介(详解)

◇◆丶佛笑我妖孽 提交于 2019-12-17 14:45:57
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 简介   前边的随笔主要介绍的requests模块的有关知识个内容,接下来看一下python的单元测试框架unittest。熟悉 或者了解java 的小伙伴应该都清楚常见的单元测试框架 Junit 和 TestNG,这个招聘的需求上也是经常见到的。python 里面也有单元 测试框架-unittest,相当于是一个 python 版的 junit。python 里面的单元测试框架除了 unittest,还有一个 pytest 框架,这个实际上用的比较少,后面有空再继续介绍和分享。unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测 试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果。 Python unit testing framework, based on Erich Gamma's JUnit and Kent Beck's Smalltalk testing framework. 翻译:python 的单元测试框架,是基于 java 的 junit 测试框架 简单的用法 1、从官网源码或者print的help里查找unittest用法 2、我们将上图的这段代码 copy 出来,单独运行,看看测试和运行结果

MimeMessage.saveChanges is really slow

随声附和 提交于 2019-12-17 14:27:48
问题 The following test is taking around 5 seconds to execute due to the inclusion of m.saveChanges() . import org.junit.Before; import org.junit.Test; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.internet.MimeMessage; import java.io.IOException; import java.util.Properties; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @Test public void test1() throws MessagingException,

java: how to mock Calendar.getInstance()?

我的梦境 提交于 2019-12-17 12:43:08
问题 In my code I have something like this: private void doSomething() { Calendar today = Calendar.getInstance(); .... } How can I "mock" it in my junit test to return a specific date? 回答1: As far as I see it you have three sensible options: Inject the Calendar instance in whatever method/class you set that day in. private void method(final Calendar cal) { Date today = cal.getTime(); } Use JodaTime instead of Calendar . This is less an option and more a case of a suggestion as JodaTime will make

JUnit: new instance before invoking each @Test method. What are the benefits?

可紊 提交于 2019-12-17 12:15:58
问题 Currently, I am reading "JUnit in action" book. In this book I found text below: JUnit creates a new instance of the test class before invoking each @Test method. This helps provide independence between test methods and avoids unintentional side effects in the test code. Because each test method runs on a new test class instance, we can’t reuse instance variable values across test methods. Now I do not see much point in this approach: For example: public class CalculatorTest { @Test public

Exception in thread “main” java.lang.NoClassDefFoundError: junit/textui/ResultPrinter

不羁岁月 提交于 2019-12-17 10:56:09
问题 I'm trying to compile my Android project in Android Studio 0.3.0. Today I get the following error: Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:188) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113) Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security

Setting up JNDI Datasource in jUnit

让人想犯罪 __ 提交于 2019-12-17 10:49:25
问题 I am trying to set up some jUnit testing. Our database is connected by the server using JNDI. We have an xml describing the setup in root.xml. How do I set up jUnit to hook up to the database? I'd prefer to have it just read the the stuff off of root.xml, but I'm open to setting it up anyway that works. 回答1: I've found this Blog: https://blogs.oracle.com/randystuph/entry/injecting_jndi_datasources_for_junit About H2 Datasource: http://www.h2database.com/javadoc/org/h2/jdbcx/JdbcConnectionPool

Spring Dependency Injection with TestNG

不打扰是莪最后的温柔 提交于 2019-12-17 10:23:04
问题 Spring support JUnit quite well on that: With the RunWith and ContextConfiguration annotation, things look very intuitive @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:dao-context.xml") This test will be able to run both in Eclipse & Maven in correctly. I wonder if there is similar stuff for TestNG. I'm considering moving to this "Next Generation" Framework but I didn't find a match for testing with Spring. 回答1: It works with TestNG as well. Your test

Gradle 5 JUnit BOM and Spring Boot Incorrect Versions

梦想与她 提交于 2019-12-17 09:53:50
问题 I am using Gradle 5's BOM (Bill of Materials) feature. This is how I describe it for my JUnit 5 dependencies: testImplementation(enforcedPlatform("org.junit:junit-bom:5.4.0")) // JUnit 5 BOM testImplementation("org.junit.jupiter:junit-jupiter-api") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") testImplementation("org.junit.jupiter:junit-jupiter-params") My assumption is that providing the BOM will resolve the versions of the dependencies to 5.4.0 . However, they get resolved to 5