0

In my Test class, I am trying to send a request to an API and compare the results with the ones that are sent from Springboot using elastic search data.

I am able to send the request via WebClient. However, the Service and Repository objects are always null. Any help would be great. Thanks

@RunWith(SpringRunner.class)
class MyTest {
    
      @Autowired
      private ESService esService; //this is null

      @Autowired
      private OtherRepository otherRepo; //this is null

      @Test
      private void testFunction(){
          TestObject Object = esService.doSomething();
          double value = new TestObject(otherRepo).getValue();
   }
}

    @Service
    public interface ESService{
        TestObject doSomething();
    }
@Service
public class ESServiceImpl implements ESService{
    
        @Autowired
        private ESRepository esRepository;
        
        TestObject doSomething(){
          return esRepository.doSomething();
      }
}
@Repository
public interface ESRepository extends ElasticsearchRepository<QueryResponse, String>, ESRepositoryCustom {
}

pom.xml

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.8.2</version>
    <scope>test</scope>
</dependency>
hamid
  • 2,033
  • 4
  • 22
  • 42
Cugomastik
  • 911
  • 13
  • 22
  • 1
    you are missing `@SpringBootTest` – hamid May 03 '22 at 10:56
  • But according to this post, @RunWith(SpringRunner.class) should be enough for @Autowired. https://stackoverflow.com/questions/58901288/springrunner-vs-springboottest – Cugomastik May 03 '22 at 11:26

0 Answers0