-
Notifications
You must be signed in to change notification settings - Fork 41.9k
Closed
Description
Hi,
hopefully I'm not doing anything wrong here. I assume that @TestComponent should be picked up when running tests with @SpringBootTest without further ado, but neither this
package com.example;
import org.springframework.boot.test.context.TestComponent;
@TestComponent
public class ToplevelTestComponent {
}together with
package com.example;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ToplevelTestComponentNotWorkingTest {
@Autowired
ToplevelTestComponent toplevelTestComponent;
@Test
public void f() {
}
}nor this (nested version)
package com.example;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestComponent;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class NestedTestComponentNotWorkingTest {
@TestComponent
static class NestedTestComponent{
}
@Autowired
NestedTestComponent nestedTestComponent;
@Test
public void f() {
}
}works. Both fail with org.springframework.beans.factory.NoSuchBeanDefinitionException.
Sample project is attached:
InitializrSpringbootProject.zip
Tested with 1.4.0, 1.4.3 and 1.5.1.
Maybe it's a documentation issue, but I don't see my error…
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: documentationA documentation updateA documentation update