junit test case for spring-integration-file - spring-boot

Am newbie to Spring. I have a spring project created using spring-integration-file (spring boot- FTP,SFTP,NFS) which will transform the file from source path to destination path.
Have to write junit test cases to test the project. It will be helpful if someone share some documents/link to write junit testcases with #RunWith(SpringRunner.class) for spring-integration-file project
Thanks in advance

You can consult Spring Integration Samples project on the matter.
Also there are a lot of JUnit tests in the spring-integration-file module of the core project per se.

Related

In intelliJ Run/Debug Configuration, how to skip spring boot tests

We have written tests using annotations like below,
#RunWith(SpringRunner.class)
#Slf4j
#SpringBootTest
in IntelliJ 2017 we run spring boot program via Run/Debug Configuration, and it automatically execute these tests. But some tests really takes a lot of time, is there a way to disable or skip these tests? Thanks a lot.
You can write a junit category of runners or right click on package name or test-class and choose Run "yourClassName", which will run only this class or all classes from selected package.

Using Spring Boot Configuration in a custom JUnit test runner that does not otherwise use Spring

I have a custom JUnit test runner that executes acceptance-level tests using a test specification format specific to my project. The system under test is using Spring Boot and takes advantage of its configuration facility. I'd like the tests to be able to read the same configuration files in the same way. Obviously, using Spring Boot Configuration itself is an answer.
I'd like to just use Spring Boot Configuration as a stand-alone library, but I'm willing to fire up Spring Boot if that's what it takes. I'm not in control of the top-level application - JUnit is. So, I don't know how to start Spring Boot when I get control inside my test runner.
I've looked at extending SpringJunit4ClassRunner but I can't keep it from looking for #Test annotations and failing when it doesn't find any. I've started to look into merging code from SpringJunit4ClassRunner into my custom runner. Before I go too far down that path, I'd appreciate input from the community.
It sounds like you simply want the application running for a standalone webservice testing. This can be done simply by scripting the "java -jar" command to run the spring boot application. However, I would question why you don't want to leverage the testing tools built into spring boot? You can fire up the entire spring boot application and write some very logical looking tests.
For example a rest api test case:
#Test
public void homePage() throwsException () {
mockMvc.perform(get("/readingList"))
.andExpect(status().isOk())
.andExpect(view().name("readingList"))
.andExpect((model().attribute("books", is(empty()))));
}

JMeter, JUnit and Spring Java configuration

Is it possible to run JMeter with the JUnit plugin/sampler and Spring Java configuration? When I try to do this, the Spring autowired beans are not being created and although the test case runs, because the beans have not been created, I get null pointer exceptions.
I am using the Spring annotation
#SpringJUnit4ClassRunner and #ContextConfiguration to configure the JUnit test (which works). The goal is to be able to write JUnit test cases that can be measured for performance using JMeter.
Yes, running JMeter with JUnit and Spring is a problem.
JMeter does not use standard JUnit runner; its specified at
User manual, point 7. There are subtle differences between standard JUnit test runners and JMeter's implementation. Because of this, #SpringJUnit4ClassRunner is becomes ignored. Workaround is to load beans as normal i.e using ApplicationContext.getBean().

running integration tests in teamcity using spring-boot and restassured

I am writing my integration tests using springboot and rest-assured and using SpringApplicationConfiguration to load the configuration.
This is what the test class annotation look like:
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = RestAPIApplication.class)
#IntegrationTest("server.port:8083") // this is the port set by my application
Now comes my real question. When I run the test class in teamcity using maven, don't I have to configure something to run the springboot server before running the integration tests?
I am new to springboot so maybe this question is very novice but please point me to the correct path.
If you're using embedded tomcat, no extra setup is needed-- simply run the maven tests.

Using JMockit and TestNG with Spring framework

Spring framework has great integration with jUnit and EasyMock. Does anyone have experience using JMockit and TestNG with Spring framework?
I have experience with TestNG with Spring framework. spring-test.jar library helps to integrate TestNG and JUnit by the way with Spring for testing purposes. If you use JMockit or not should not affect the way you use TestNG-SprintTest-Spring integration.

Resources