First, Android junit Runner introduction 1.Android junit Runner1) is a test runner for running Junit3 and JUNIT4 Android test packages2) Replace the instrumentation test Runner (an older test runner)3) Support Instrumentation Test
All test methods in JUnit are performed by the Test Runner. JUnit unit tests provide a default test runner Blockjunit4classrunner, but there is no restriction that the default runner must be used.
We can customize our own running device as needed, as long as we inherit from
"Foreword" uncomfortable ...
Eclipse always error: No tests found with Test runner JUnit4
First, here are a few points
1 Have you imported the JUnit package (which you brought in eclipse) if you used the spring test class to import the Spring-test package
2 Whether your package version is too low
3 have not used
problem
In Java, JUnit is generally used as the unit test framework, and the objects to be tested are typically service and DAO, or Remoteservice and controller. All of these test objects are basically spring-managed and are not directly new. Each TestCase class is created by JUnit. How to inject these dependencies into each testcase instance. expected effect
We
Use Junit in the SpringBoot Web Project
Create a common Java class. In Junit4, you no longer need to inherit the TestCase class.Because we are a Web project, add annotations to the created Java class:
@ RunWith (SpringJUnit4ClassRunner. class) // SpringJUnit support, which introduces Spring-Test framework support! @ SpringApplicationConfiguration (classes = SpringBootSampleApplication. class) // specify th
Recently, at the request of the boss, study the spring test related things, and strive to make a convenient use of testing tools, for a spring is not familiar to the JUnit people this is a big pit, swept aside spring test document did not feel any gain, What spring does is j
@BeforeClass acting on a classExecutes once for all methods in a classproperty to be declared as static.@Before Acting on methodsEvery test method is executed once@Test Join the testJUnit order problem, performed alphabetically. To execute in an orderly manner, you can use testng,testng to add dependentJUnit Union Spring@RunWith (Springjunit4classrunner. Class) //Spring and
the entire class is ignored if it is used to decorate the class@Ignore ("Not Ready Yet")@Test@RunWithThere are many runner in JUnit, they are responsible for invoking your test code, each runner has its own special features, and you need to choose different runner to run your test code as needed.If we are simply doing
Direct use of JUnit to test the shortage of Spring programs
you need to manually fetch the bean using hard coding: in the test case, we need to get the target Bean to be tested from the SPIRNG container by means of the Applicationcontext.getbean () method, and also to do the modeling operation.
The database site is vulnerable to damage: The test method may make changes to the database records,
Reference article: Spring MVC full Annotation configuration-no web. xmlThe purpose of unit testing, in short, is to test all logic after we add or change some code, especially after we have modified it later (whether adding new features or modifying bugs), we can do the work of re-testing. To reduce the problem that we have solved even before the release of the issue.Spring MVC testing often seems more complex. In fact his difference is that he needs
Spring-based reusable Junit test class design
We do not need to perform unit tests during SSH projects. In many cases, we do not want the unit test results to affect the real database, then we need to use transactions for management.
The JUnit Test base class is as follows:
Package com. sms. test. base; import org. junit
"Spring" JUnit loading spring containers for unit testingRead Catalogue
> Basic Construction
> Common usage
If we need to do unit testing of our service methods, and just like spring as an IOC container, we can configure JUnit to load the
When you write JUnit single measurements using spring, you can use the annotations to start and configure a jar package for spring Pom to introduce the
testing base Classes and JUnit tests
Package com.simple.test;
Import Org.junit.runner.RunWith;
Import org.springframework.test.context.ContextConfiguration;
Imp
the Runner@Suite. suiteclasses ({calculatortest.class, parameterstest.class})Specify the class to testpublic class Testall{}@RunWith (Suite.class)@SuiteClasses (Testall.class)In addition to specifying a class, you can also specify a suite classpublic class TestAll2{}
4. Junit main syntax
JUNIT4 Use Java5 the annotations in the ( annotation ), the following is JUNIT4 a few common annotation :
Http://www.51testing.com/html/14/n-1408814.html1. Test the bean injected directly in spring (in DAO, for example):Adding @runwith annotations on a test class specifies that the test runner using springjunit, @ContextConfiguration annotations Specify the location of the spring configuration file for the test, we can inject the bean we need to test,
Recent company projects and their own projects have used spring integrated junit for unit testing, summarizing several basic uses:1. Test the bean injected directly in spring (in DAO, for example):Adding @runwith annotations on a test class specifies the test runner using Springjunit, @ContextConfiguration note Specifi
Packagecn.mf.b_test;ImportJavax.annotation.Resource;Importorg.junit.Test;ImportOrg.junit.runner.RunWith;Importorg.springframework.test.context.ContextConfiguration;ImportOrg.springframework.test.context.junit4.SpringJUnit4ClassRunner;ImportCn.mf.bean.User;//help us create a container@RunWith (Springjunit4classrunner.class)//specify which configuration file to use when creating the container@ContextConfiguration ("Classpath:applicationContext.xml") Public classDemo {//injecting an object named us
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.