JBPM 6 - 2.0.0 - Unit Testing Introduction

From Training Material
Revision as of 15:32, 17 November 2016 by Wang Hao (talk | contribs) (JBPM 6 - 2.0.0 - Unit Testing Introduction)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

JBPM 6 - 2.0.0 - Unit Testing Introduction 单元测试介绍

Unit testing 单元测试

  • Unit testing is a software testing method by which individual units of source code are tested to determine if they are fit for use
单元测试是一个软件测试方法,人们经过测试代码的独立单元,从而决定是否代码可以投入使用
  • Unit tests are short code fragments created by programmers or testers during the development process.
单元测试代码是开发过程中程序员或测试人员写的很短的代码片段
  • Unit testing provides a sort of living documentation of the system.
单元测试相当于提供了一套活着的系统文档

JUnit

  • JUnit is a unit testing framework for the Java programming language.

<source lang="java"> public class TestFoobar {

   @Test
   public void testOneThing() {
       // Code that tests one thing
   }

   @Test
   public void testAnotherThing() {
       // Code that tests another thing
   }

} </source>

Assertion

  • An assertion is a true–false statement placed in a program to indicate that the developer thinks 'that the predicate is always true at that place.
  • If an assertion evaluates to false at run-time, an assertion failure results, which typically causes execution to abort.

<source lang="java"> x = 1; assert (x > 0); x++; assert (x > 1); </source>

Appendix

assert methods used in jBPM

<source lang="java">

assertNodeTriggered(processInstance.getId(),"Book Hotel"); assertNodeTriggered(processInstance.getId(), "StartProcess", "Hello", "EndProcess"); // checks whether the given node(s) was/were executed during the process execution

assertProcessInstanceActive(processInstanceId, ksession) // checks whether the process instance is active

assertProcessInstanceCompleted(processInstanceId, ksession); // checks whether the process instance has completed successfully

</source>

java operators

Simple Assignment Operator

=       Simple assignment operator

Arithmetic Operators

+       Additive operator (also used for String concatenation)
-       Subtraction operator
*       Multiplication operator
/       Division operator
%       Remainder operator

Equality and Relational Operators

==      equal to
!=      not equal to
>       greater than
>=      greater than or equal to
<       less than
<=      less than or equal to
!       logical complement operator; inverts the value of a boolean

Conditional Operators

&& Conditional-AND
|| Conditional-OR