Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot can't run single test in IntelliJ

This started happening recently, but I'm not sure what changed to cause it.

  • When I run all tests from IntelliJ, all is well. Also the gradle build is fine.
  • When I run a single unit test, all is well.
  • When I run a single web integration test, it fails because a config class has all null properties.

The config class looks like (Kotlin):

@Component
@ConfigurationProperties(prefix = "api")
public open class ApiConfigImpl : ApiConfig
{ 

A test looks like:

@RunWith(SpringJUnit4ClassRunner::class)
@ContextConfiguration(classes = arrayOf(ApplicationAssembly::class), loader = SpringApplicationContextLoader::class)
@WebIntegrationTest
open class CandidateProfileControllerTest
{

    @Inject lateinit var profileRepo: CandidateProfileRepository
    //etc a few more deps used to setup test data

    @Test
    open fun getById()
    {
        val greg = CandidateProfile("123", "12312", "Greg", "Jones",   dateOfBirth = Date(), gender = Gender.MALE,
            biography = "ABC", maxMatchableAge = null,   maxMatchableDistance = null)
        profileRepo.save(greg)

        val auth = given().header("content-type", "application/json")
            .body(testCredentials)
            .post("/authorization/social").peek().asString()
        val accessToken: String = from(auth).get("accessToken")

        given().header("Access-Token", accessToken).
            header("API-Key", testAPIKey()).
            get("/profile/${greg.id}").
            peek().then().
            body("stageName", notNullValue())
    }

I'm not sure what information I can add. Based on the limited information provided:

  • Is this a known problem with a known solution?
like image 998
Jasper Blues Avatar asked Feb 03 '16 12:02

Jasper Blues


People also ask

How do I run a single test case in IntelliJ?

Right-click a test on the Test Runner tab of the Run tool window and select Run 'test name'.

Why is IntelliJ not running tests?

Check in Project settings -> Modules that you test package is marked as Tests. Right click on the test class name either in the code window or in the project panel, and select Run <classname>. If you don't see the run menu in the popup then you haven't selected a test or you don't have junit plugin installed.

How do I run a single test file in JUnit IntelliJ?

Open the class where the tests are located and check the part where inteliJ shows the the number of lines, at the beginning of each test method there is a green icon (looks like a play button) just hit that icon and the specific test method will be executed.


1 Answers

This is a bug, logged in the IntelliJ/Kotlin tracker, with a pending fix.

like image 71
Jasper Blues Avatar answered Sep 28 '22 21:09

Jasper Blues