the same package, i.e. their package names should be the same.
In this way, you do not have to import the package that contains the source code in your test class, because they are located under the same package.
3. Naming rules for test classes :
Add test before or after the class name to be tested.
After this step is complete, the project directory is as fo
corresponding four methods and click Finish. A test class is automatically generated, but we still need to modify the class to the following code.
1 package Org. logback. test; 2 3 Import static Org. JUnit. assert. *; 4 5 import Org. JUnit. after; 6 Import Org.
exiting PE.
Code example:
Original class: public class rosterqueryedu
Method to be tested in this class: Public Boolean rosterqueryedu (vwsession)
Test code (compare the use of assertions and non-assertions in the test method ):
/**
*Function:
*Author: Chen Weidong
*Data time: Jun 30,201 1 10:51:56
*/
Package com.ibm.filenet.edu;
Import filenet. VW. API. vwsession;
Import
A simple framework
JUnit is an open source testing framework developed by Erich Gamma and Kent Beck, and JBuilder integrates the framework and expands on it. The reason why JUnit is popular and respected by the vast number of developers is that it is real and powerful, and the second is because it is simple. A product or framework to be able to have vitality, it is best to have such characteristics.
Simply
);SetContentView (R. layout. main );MyText = (TextView) findViewById (R. id. text1 );Button = (Button) findViewById (R. id. button1 );Button. setOnClickListener (new OnClickListener (){@ OverridePublic void onClick (View arg0 ){MyText. setText ("Hello Android ");}});}Public int add (int I, int j ){Return (I + j );}}The function of this program is relatively simple. After clicking the button, the content of TextView changes from Hello to Hello Android. at the same time, in this class, I also wro
= Loggerfactory.getlogger (Studentcontroller.class); @Rule//Note here that the use of @rule annotations must be public PublicOutputcapture capture =Newoutputcapture (); @Test Public voidtest4 () {System.out.println ("HelloWorld"); Logger.info ("Logo log will also be captured by capture test output"); Assertthat (Capture.tostring (), Matchers.containsstring ("World")); }}Some of the assertion methods in
junit Unit Test Basics Essentials1.JUnit is a framework for testing code that is designed to ensure that the code is correct, not the code. 2. The test class is generally not put together with the target class, but the compiled class file is put together. 3. Unit testing is mainly to
public void Wordformat4dbtogether () {String target = "Employeeainfo";String result = worddealutil.wordformat4db (target);Assertequals ("Employee_a_info", result);}4) View the results of the analysis run and modify the error codeRun the test again. The JUnit runtime interface prompts us to have two test cases failing the tes
Testequals () {//Put the test code in TestequalsMoney m12chf= New Money ("CHF"); The bank and the next line do some initializationMoney m14chf= New Money ("CHF");Assert.asserttrue (!m12chf.equals (null));//test for different situationsAssert.assertequals (M12CHF, M12CHF);Assert.assertequals (M12CHF, New Money ("CHF")); (1)Assert.asserttrue (!m12chf.equals (M14CH
, negative, and zero. So let's proceed as follows. First, right-click a new juint test case in the calculator class and name it calculatorsquaretest. Then the code of this class is modified as follows:
1 package Org. logback. test; 2 3 Import static Org. JUnit. assert. *; 4 5 import Java. util. arrays; 6 Import Java. u
Android uses its own Junit to create a test project, androidjunit
1. Create an Android Project
Package com. shellway. junit; public class Service {public int divide (int a, int B) {return a/B ;}}Service. java. package com. shellway. junit; import junit. framework.
, remember to introduce JUNIT Framework and guide package2: @before @after before and after the test method execution, you can load and close some resources1 privateString Driverclassname; 2 PrivateString URL; 3 PrivateString username; 4 private String password; 5 private Connection Conn; 6 7 @Before 8 public void before () {9 DRIVERCL Assname = "Com.mysql.jdbc.Driver" ; url = "Jdbc:mysql://localhost:330
to throw errors, as follows:Later, when we validate the logic of the code, we can directly use the various static methods provided in the Assert class, without having to write the code to determine whether the logic is correct.Junit3 the inside of the assert can also be used, as long as the test class to inherit the TestCase class on the line.Hamcrest, the jar p
JUnit 3.8
1. Add the JUnit Library Under eclipse
Right-click Project> build path> Add library> and select JUnit.
2. Download the jar package from the official website and import it to the project.
3. Write test cases. Create SRC fold under the same level of SRC and name it tes
1 /**Activitispringjuinittest.java2 * Author: Feng Mengwao ^_^3 * dates:2015 Year September 2 afternoon 2:16:544 * Class:activiti's Junit test5 */6 //Specify the run environment to use for spring's test package (Spring-test.jar)7@RunWith (Springjunit4classrunner.class)8 //inject some configuration information9@ContextConfiguration (locations= "Classpath:applicationConfig.xml") Ten Public classActivitispri
steps:1. New package (generally named *. Test, the testing class and the development class are placed in different packages)2. New JUnit Text case (generally named *test)3. Select the method you want to test4. You can download the latest jar package, or you can select the system's own: www.junit.orgStatic Introduction:import static org.junit.assert.*;a static cla
After the configuration is successful, you need to start the test case!
Package com. CMC. controller;Import javax. annotation. Resource;Import org. junit. Test;Import org. junit. runner. RunWith;Import org. springframework. test. context. ContextConfiguration;Import org. sp
methods;Copy Codepublic static method[] Getdeclaredmethods (classcomparatorMethod[] methods = Clazz.getdeclaredmethods ();if (comparator! = null) {Arrays.sort (methods, comparator);//Sort by specified order}return methods;}Copy CodeThe three execution sequences are defined as follows:Copy Code/*** Sorts the test methods by the method name, in lexicographic order,* With {@link method#tostring ()} used as a
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.