junit

Spring Boot JPA metamodel must not be empty! when trying to run JUnit / Integration Tests

孤人 提交于 2020-05-17 08:18:06
问题 Am using Spring Boot, JUnit 4 & Mockito in a maven based project to tests my Spring Boot Microservice REST API. So, on startup, the DataInserter class loads data from owner.json and cars.json. Normally, via my REST calls, everything works, but it seems I have something wrong with setting up unit tests and integration tests. Project structure: myapi │ ├── pom.xml │ ├── src ├── main │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ └── myapi │ │ │ │ │ ├── MyApplication.java │ │ │ │ │ ├── bootstrap │ │

Unit testing LiveData observerForever results in NullPointer Exception with Junit5

拟墨画扇 提交于 2020-05-17 07:09:06
问题 I am using Android databinding to listen to live data changes and I would like to observe changes on the viewmodel level (Rather then observing on fragment and then sending a callback to the viewmodel) The observerForever is interesting as it serves the purpose for me. However when I run a test I get the following error: java.lang.NullPointerException at androidx.arch.core.executor.DefaultTaskExecutor.isMainThread(DefaultTaskExecutor.java:77) at androidx.arch.core.executor.ArchTaskExecutor

Re-wire spring bean in @Before method

杀马特。学长 韩版系。学妹 提交于 2020-05-17 06:34:33
问题 I want to unit test an @Controller -annotated class, using JUnit. Is it possible for Spring to reset ("re-wire") the controller to its default injected state ? There would be no problem building a all new controller object. A workaround I found is to set the constructor's visibility to protected and execute ControllerObj controllerObj = new ControllerObj() at the beginning of @Before -annotated class but I obviously do not want to increase contructor's visibility just for testing purpose. 回答1

@SpringBootTest resulting in 'No tests found for given includes'

不问归期 提交于 2020-05-15 09:03:56
问题 I have simple unit test which starts my app and tests that certain services have been instantiated. Kind of just a sanity check. However, these tests are not being run in my full test suite, and when run individually i get the error No tests found for given includes: [com.example.AppTest](filter.includeTestsMatching) This is my unit test import com.sblukcic.cli.flags.CLIParser; import org.junit.Rule; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit

Java JUnit 5 annotations differences

心不动则不痛 提交于 2020-05-12 13:59:51
问题 I see there was introduced the new JUnit Jupiter according to JUnit 5 User Guide. JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage I am confused about the same-named annotations I use across the library. Is there any significant difference between these two ones? org.junit.Test org.junit.jupiter.api.Test The description from the linked page above explains the annotation org.junit.jupiter.api.Test as following: Denotes that a method is a test method. Unlike JUnit 4’s @Test annotation,

Java JUnit 5 annotations differences

◇◆丶佛笑我妖孽 提交于 2020-05-12 13:59:48
问题 I see there was introduced the new JUnit Jupiter according to JUnit 5 User Guide. JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage I am confused about the same-named annotations I use across the library. Is there any significant difference between these two ones? org.junit.Test org.junit.jupiter.api.Test The description from the linked page above explains the annotation org.junit.jupiter.api.Test as following: Denotes that a method is a test method. Unlike JUnit 4’s @Test annotation,

Selenium Close File Picker Dialog

瘦欲@ 提交于 2020-05-10 18:39:09
问题 We are using Selenium-Webdriver on Jenkins box (running linux), to drive Firefox for testing a fairly complex web app. The web app requires the uploading of a photo for testing, and we have achieved that by using sendkeys to the input file dialog. Unfortunately (perhaps due to the way the uploader works, it is plupload and uploads through XHR and not a FORM post) the File Picker Dialog never closes. While this was slightly annoying, in the past the tests still passed fine. Switching from

Why I received an Error 403 with MockMvc and JUnit?

大城市里の小女人 提交于 2020-05-09 19:00:31
问题 I have a spring mvc (3.2.5) application with spring security (3.2). I configured my SecurityConfig.class with this method : @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers("/*").permitAll().and() .formLogin().successHandler(successHandler) .defaultSuccessUrl("/") .failureHandler(failureHandler).failureUrl("/login?error=true") .permitAll().and().logout() .permitAll(); http.authorizeRequests().antMatchers("/resources/**").permitAll()

Unit testing a broadcast receiver?

佐手、 提交于 2020-05-09 17:44:04
问题 Here's a BroadcastReceiver from my project, which I'm looking to unit test. When the user makes a phone call, it grabs the phone number, and sets up an intent to start a new activity, passing in the phone number. public class OutgoingCallReceiver extends BroadcastReceiver { @Override public void onReceive(Context xiContext, Intent xiIntent) { if (xiIntent.getAction().equalsIgnoreCase(Intent.ACTION_NEW_OUTGOING_CALL)) { String phoneNum = xiIntent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

Java自动化测试框架-08

感情迁移 提交于 2020-05-09 14:06:59
转自: https://www.cnblogs.com/du-hong/p/11810569.html 一、并行性和超时 您可以指示TestNG以各种方式在单独的线程中运行测试。 可以通过在suite标签中使用 parallel 属性来让 测试 方法运行在不同的线程中。这个属性可以带有如下这样的值: 二、并行套件(suites) 如果您正在运行多个套件文件(例如“ java org.testng.TestNG testng1.xml testng2.xml”),并且希望每个套件在单独的线程中运行,则这个很有用。您可以使用以下命令行标志来指定线程池的大小: java org.testng.TestNG -suitethreadpoolsize 3 testng1.xml testng2.xml testng3.xml 相应的ant任务名称为suitethreadpoolsize。 三、并行测试,类和方法 在并行于<suite>标记属性可以取下列值之一: <suite name="My suite" parallel="methods" thread-count="5"> <suite name="My suite" parallel="tests" thread-count="5"> <suite name="My suite" parallel="classes" thread