I have used TestNG+Rest Assured for rest api service testing(application is written based on Spring framework) and just want to know if it is better to use Spring test framework alone or integration TestNG+Spring test.
Thanks.
Use the combination of both.
TestNG will act as full featured test framework and Spring Test framework to mock spring beans (In other words, to get the out of the box spring support).
Related
Most examples around the Web for doing Spring integration tests with Neo4j are still on JUnit 4, and use the Neo4jRule.
How do we create a setup for Neo4j + Spring + JUnit 5?
If you are testing on embedded, please use the Test Harness with a simple Spring Configuration.
Here are some examples:
https://medium.com/neo4j/testing-your-neo4j-based-java-application-34bef487cc3c
https://github.com/michael-simons/neo4j-sdn-ogm-tips/tree/master/examples/using-the-test-harness
https://github.com/michael-simons/neo4j-sdn-ogm-tips/tree/master/examples/using-testcontainers
https://github.com/neo4j/neo4j-java-driver-spring-boot-starter/tree/master/examples/testing-with-neo4j-harness
I would have an eye on the above ^^
This and test containers will be our way forward.
Note: The #Neo4jExtension is mostly used internally by the core team and not recommended for general use.
I am looking for a feature that is similar to what #WebMvcTest does.
What #WebMvcTest does .
1. only instantiating the web layer, not the whole context
2. Only works with Spring Boot application (as it is in the package - org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest).
What I want to achieve
Write unit test case on Controller only instantiating the web layer, not the whole context on Spring MVC application (not Spring Boot application)?
Is there a way to achieve that?
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()))));
}
Is there any specific approach already defined or used by any one for unit testing applications using Struts, Springs, Hibernate technologies ?
What are different mocking apis we can use ?
Note: I don't want want any solution to individually unit test these technologies.
You can inject mock Spring facades into your Struts actions, and unit-test the Struts actions. You can inject mock Spring repositories/DAOs into your Spring facades and unit-test these facades. And you can use DBUnit (or another similar tool) to populate a test database before each repository test.
Choose the mocking API you like the most. There are sevaral ones: Mockito, EasyMock, JMock, etc.
If you want to test the whole app, you're not doing unit tests anymore, but integration tests. And mocking would go against your goal. If that's what you want to do, you could use Selenium or HtmlUnit to test the application.
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.