ɎȿȾȿɊȺɅɖɇɈȿ ȺȽȿɇɌɋɌȼɈ ɉɈ ɈȻɊȺɁɈȼȺɇɂɘ ȽɈɋɍȾȺɊɋɌȼȿɇɇɈȿ ɈȻɊȺɁɈȼȺɌȿɅɖɇɈȿ ɍɑɊȿɀȾȿɇɂȿ ȼɕɋɒȿȽɈ ɉɊɈɎȿɋɋɂɈɇȺɅɖɇɈȽɈ ɈȻɊȺɁɈȼȺɇɂə «ȼɈɊɈɇȿɀɋɄɂɃ ȽɈɋɍȾȺɊɋɌȼȿɇɇɕɃ ɍɇɂȼȿɊɋɂɌȿɌ»
ȼ.Ⱥ. ɋɬɟɩɚɧɰɨɜ ɉɊȺɄɌɂɑȿɋɄȺə ɊȺȻɈɌȺ ȼ ECLIPSE 3.2 ɍɱɟɛɧɨ-ɦɟɬɨɞɢɱɟɫɤɨɟ ɩɨɫɨɛɢɟ ɞɥɹ ɜɭɡɨɜ
ɂɡɞɚɬɟɥɶɫɤɨ-ɩɨɥɢɝɪɚɮɢɱɟɫɤɢɣ ɰɟɧɬɪ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ 2007
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɍɬɜɟɪɠɞɟɧɨ ɧɚɭɱɧɨ-ɦɟɬɨɞɢɱɟɫɤɢɦ ɫɨɜɟɬɨɦ ɮɚɤɭɥɶɬɟɬɚ ɤɨɦɩɶɸɬɟɪɧɵɯ ɧɚɭɤ 21.ɦɚɪɬɚ 2007 ɝ., ɩɪɨɬɨɤɨɥ ʋ 3
Ɋɟɰɟɧɡɟɧɬ ɞɨɰɟɧɬ Ⱥ.ȼ. ɋɵɱɟɜ
ɍɱɟɛɧɨ-ɦɟɬɨɞɢɱɟɫɤɨɟ ɩɨɫɨɛɢɟ ɩɨɞɝɨɬɨɜɥɟɧɨ ɧɚ ɤɚɮɟɞɪɟ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɢ ɢɧɮɨɪɦɚɰɢɨɧɧɵɯ ɬɟɯɧɨɥɨɝɢɣ ɝɨɫɭɧɢɜɟɪɫɢɬɟɬɚ. ɉɪɟɞɧɚɡɧɚɱɟɧɨ ɞɥɹ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɧɚ ɥɚɛɨɪɚɬɨɪɧɵɯ ɡɚɧɹɬɢɹɯ ɢ ɞɥɹ ɫɚɦɨɫɬɨɹɬɟɥɶɧɨɣ ɪɚɛɨɬɵ ɫɬɭɞɟɧɬɨɜ ɞɧɟɜɧɨɝɨ ɨɬɞɟɥɟɧɢɹ ɮɚɤɭɥɶɬɟɬɚ ɤɨɦɩɶɸɬɟɪɧɵɯ ɧɚɭɤ ɩɨ ɤɭɪɫɚɦ «əɡɵɤ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ Java» ɢ «Ɋɚɡɪɚɛɨɬɤɚ ɩɪɢɥɨɠɟɧɢɣ ɧɚ Java».
Ⱦɥɹ ɫɩɟɰɢɚɥɶɧɨɫɬɢ 071900 (230201) – ɂɧɮɨɪɦɚɰɢɨɧɧɵɟ ɫɢɫɬɟɦɵ ɢ ɬɟɯɧɨɥɨɝɢɢ ɢ ɧɚɩɪɚɜɥɟɧɢɹ 511800 – Ɇɚɬɟɦɚɬɢɤɚ. Ʉɨɦɩɶɸɬɟɪɧɵɟ ɧɚɭɤɢ
2
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ȼɜɟɞɟɧɢɟ ɜ Eclipse Eclipse – ɷɬɨ ɪɚɫɲɢɪɹɟɦɚɹ ɫɪɟɞɚ ɪɚɡɪɚɛɨɬɤɢ Integrated Development Environment (IDE) ɫ ɨɬɤɪɵɬɵɦ ɢɫɯɨɞɧɵɦ ɤɨɞɨɦ (OpenSource). ɉɪɨɟɤɬ ɛɵɥ ɡɚɩɭɳɟɧ ɜ ɧɨɹɛɪɟ 2001 ɝɨɞɚ, ɤɨɝɞɚ IBM ɩɟɪɟɞɚɥɚ ɢɫɯɨɞɧɵɣ ɤɨɞ ɫɜɨɟɝɨ Websphere Studio Workbench ɫɬɨɢɦɨɫɬɶɸ 40 ɦɢɥɥɢɨɧɨɜ ɞɨɥɥɚɪɨɜ ɧɚ OpenSource ɢ ɫɮɨɪɦɢɪɨɜɚɥɚ ɤɨɧɫɨɪɰɢɭɦ Eclipse ɞɥɹ ɭɩɪɚɜɥɟɧɢɹ ɩɪɨɞɨɥɠɚɸɳɟɣɫɹ ɪɚɡɪɚɛɨɬɤɨɣ. Ʉɨɧɫɨɪɰɢɭɦ ɧɚɰɟɥɟɧ ɧɚ ɬɪɢ ɝɥɚɜɧɵɯ ɩɪɨɟɤɬɚ: 1. The Eclipse (http://www.eclipse.org/eclipse/) ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ Eclipse IDE – ɩɥɚɬɮɨɪɦɵ, ɫɨɞɟɪɠɚɳɟɣ ɢ ɢɫɩɨɥɧɹɸɳɟɣ ɢɧɫɬɪɭɦɟɧɬɵ Eclipse, ɢɧɫɬɪɭɦɟɧɬɨɜ ɪɚɡɪɚɛɨɬɤɢ ɞɥɹ Java – Java Development Tools (JDT) (http://www.eclipse.org/jdt/) ɢ ɫɪɟɞɵ ɪɚɡɪɚɛɨɬɤɢ Plug-In – Plug-In Development Environment (PDE) (http://www.eclipse.org/pde/), ɩɨɡɜɨɥɹɸɳɢɯ ɪɚɫɲɢɪɹɬɶ ɩɥɚɬɮɨɪɦɭ. 2. Eclipse Tools (http://www.eclipse.org/projects/) ɢɦɟɟɬ ɫɜɨɟɣ ɰɟɥɶɸ ɫɨɡɞɚɧɢɟ ɢɧɫɬɪɭɦɟɧɬɨɜ ɞɥɹ ɩɥɚɬɮɨɪɦɵ Eclipse. ȼ ɬɟɤɭɳɟɣ ɪɚɡɪɚɛɨɬɤɟ ɧɚɯɨɞɹɬɫɹ ɩɨɞɩɪɨɟɤɬɵ ɫɨɡɞɚɧɢɹ IDE ɞɥɹ Cobol, IDE ɞɥɹ C/C++, ɚ ɬɚɤɠɟ ɢɧɫɬɪɭɦɟɧɬɚ ɞɥɹ ɩɨɫɬɪɨɟɧɢɹ EMF ɦɨɞɟɥɟɣ. 3. The Eclipse Technology (http://www.eclipse.org/technology/) ɨɬɜɟɬɫɬɜɟɧɟɧ ɡɚ ɬɟɯɧɨɥɨɝɢɱɟɫɤɢɟ ɪɚɡɪɚɛɨɬɤɢ, ɷɜɨɥɸɰɢɸ ɢ ɨɛɭɱɟɧɢɟ ɢɫɩɨɥɶɡɨɜɚɧɢɸ ɩɥɚɬɮɨɪɦɵ Eclipse. ɉɥɚɬɮɨɪɦɚ Eclipse ɜ ɫɨɱɟɬɚɧɢɢ ɫ JDT ɜɤɥɸɱɚɟɬ ɦɧɨɝɢɟ ɢɡ ɜɨɡɦɨɠɧɨɫɬɟɣ, ɤɨɬɨɪɵɟ ɜɤɥɸɱɚɸɬɫɹ ɜ ɤɨɦɦɟɪɱɟɫɤɢɟ IDE: ɪɟɞɚɤɬɨɪ ɫ ɩɨɞɫɜɟɬɤɨɣ ɫɢɧɬɚɤɫɢɫɚ, ɢɧɤɪɟɦɟɧɬɚɥɶɧɚɹ ɤɨɦɩɢɥɹɰɢɹ ɤɨɞɚ, ɩɨɬɨɤɨɛɟɡɨɩɚɫɧɵɣ ɨɬɥɚɞɱɢɤ, ɧɚɜɢɝɚɬɨɪ ɩɨ ɤɥɚɫɫɚɦ, ɦɟɧɟɞɠɟɪɵ ɮɚɣɥɨɜ ɢ ɩɪɨɟɤɬɨɜ, ɚ ɬɚɤɠɟ ɢɧɬɟɪɮɟɣɫɵ ɤ ɫɬɚɧɞɚɪɬɧɵɦ ɫɢɫɬɟɦɚɦ ɤɨɧɬɪɨɥɹ ɢɫɯɨɞɧɵɯ ɬɟɤɫɬɨɜ, ɬɚɤɢɦ ɤɚɤ CVS ɢ ClearCase. ɉɪɨɟɤɬ Eclipse ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɩɟɪɜɭɸ ɫɬɨɥɶ ɦɨɳɧɨ ɩɨɞɞɟɪɠɚɧɧɭɸ ɦɢɪɨɜɵɦ IT-ɫɨɨɛɳɟɫɬɜɨɦ ɩɨɩɵɬɤɭ ɫɨɡɞɚɧɢɹ ɟɞɢɧɨɣ ɨɬɤɪɵɬɨɣ ɢɧɬɟɝɪɢɪɨɜɚɧɧɨɣ ɩɥɚɬɮɨɪɦɵ ɪɚɡɪɚɛɨɬɤɢ ɩɪɢɥɨɠɟɧɢɣ, ɨɛɥɚɞɚɸɳɟɣ ɧɚɞɟɠɧɨɫɬɶɸ, ɮɭɧɤɰɢɨɧɚɥɶɧɨɫɬɶɸ ɢ ɭɪɨɜɧɟɦ ɤɚɱɟɫɬɜɚ ɤɨɦɦɟɪɱɟɫɤɨɝɨ ɩɪɨɞɭɤɬɚ. Ɏɚɤɬɢɱɟɫɤɢ ɷɬɚ ɩɥɚɬɮɨɪɦɚ ɩɪɟɞɧɚɡɧɚɱɟɧɚ ɞɥɹ ɜɫɟɝɨ ɢ ɧɢ ɞɥɹ ɱɟɝɨ ɤɨɧɤɪɟɬɧɨ: ɨɧɚ ɩɪɟɞɫɬɚɜɥɹɟɬ ɫɨɛɨɣ ɨɫɧɨɜɭ, ɢɦɟɸɳɭɸ ɛɥɨɱɧɭɸ ɫɬɪɭɤɬɭɪɭ ɢ ɢɧɬɟɝɪɢɪɭɸɳɭɸ ɢɧɫɬɪɭɦɟɧɬɵ ɪɚɡɪɚɛɨɬɤɢ ɉɈ ɪɚɡɥɢɱɧɵɯ ɩɪɨɢɡɜɨɞɢɬɟɥɟɣ ɞɥɹ ɫɨɡɞɚɧɢɹ ɩɪɢɥɨɠɟɧɢɣ ɧɚ ɥɸɛɨɦ ɹɡɵɤɟ, ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɥɸɛɵɯ ɬɟɯɧɨɥɨɝɢɣ ɢ ɞɥɹ ɥɸɛɨɣ ɩɪɨɝɪɚɦɦɧɨɣ ɩɥɚɬɮɨɪɦɵ. ȼɨɤɪɭɝ ɩɪɨɟɤɬɚ Eclipse ɜ ɧɚɫɬɨɹɳɟɟ ɜɪɟɦɹ ɫɮɨɪɦɢɪɨɜɚɧɨ ɫɨɨɛɳɟɫɬɜɨ ɤɪɭɩɧɟɣɲɢɯ IT-ɤɨɦɩɚɧɢɣ, ɫɪɟɞɢ ɤɨɬɨɪɵɯ Borland, IBM, SAP AG, RedHat ɢ ɞɪɭɝɢɟ. Ɍɚɤɠɟ Eclipse ɩɪɟɞɥɚɝɚɟɬ ɦɧɨɠɟɫɬɜɨ ɭɧɢɤɚɥɶɧɵɯ ɜɨɡɦɨɠɧɨɫɬɟɣ, ɧɚɩɪɢɦɟɪ ɪɟɮɚɤɬɨɪɢɧɝ ɤɨɞɚ (http://www.refactoring.com/), ɚɜɬɨɦɚɬɢɱɟɫɤɨɟ ɨɛɧɨɜɥɟɧɢɟ ɢɥɢ ɭɫɬɚɧɨɜɤɚ ɤɨɞɚ (ɫ ɩɨɦɨɳɶɸ Ɇɟɧɟɞɠɟɪɚ Ɉɛɧɨɜɥɟɧɢɣ), 3
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɫɩɢɫɨɤ ɬɟɤɭɳɢɯ ɡɚɞɚɱ, ɨɬɥɚɞɤɭ ɦɨɞɭɥɟɣ ɫ ɩɨɦɨɳɶɸ JUnit (http://www.junit.org/) ɢ ɢɧɬɟɝɪɚɰɢɸ ɫ ɢɧɫɬɪɭɦɟɧɬɨɦ ɤɨɦɩɨɧɨɜɤɢ Jakarta Ant (http://jakarta.apache.org/ant/). ɇɟɫɦɨɬɪɹ ɧɚ ɛɨɥɶɲɨɟ ɱɢɫɥɨ ɫɬɚɧɞɚɪɬɧɵɯ ɜɨɡɦɨɠɧɨɫɬɟɣ, Eclipse ɨɬɥɢɱɚɟɬɫɹ ɨɬ ɬɪɚɞɢɰɢɨɧɧɵɯ IDE ɩɨ ɪɹɞɭ ɨɫɨɛɟɧɧɨɫɬɟɣ. ɇɚɜɟɪɧɨ, ɫɚɦɨɟ ɢɧɬɟɪɟɫɧɨɟ ɜ Eclipse ɬɨ, ɱɬɨ ɨɧɚ ɩɨɥɧɨɫɬɶɸ ɧɟɡɚɜɢɫɢɦɚ ɨɬ ɩɥɚɬɮɨɪɦɵ ɢ ɹɡɵɤɚ. ɉɨɦɢɦɨ ɹɡɵɤɨɜ, ɩɨɞɞɟɪɠɢɜɚɟɦɵɯ ɤɨɧɫɨɪɰɢɭɦɨɦ ɜ ɧɚɫɬɨɹɳɢɣ ɦɨɦɟɧɬ (Java, Cobol, C/C++), ɜɟɞɭɬɫɹ ɪɚɡɪɚɛɨɬɤɢ ɩɨ ɞɨɛɚɜɥɟɧɢɸ ɜ Eclipse ɩɨɞɞɟɪɠɤɢ ɬɚɤɢɯ ɹɡɵɤɨɜ, ɤɚɤ Python, Eiffel, PHP, Ruby ɢ C#. Ʉɨɧɫɨɪɰɢɭɦ ɩɪɟɞɨɫɬɚɜɥɹɟɬ ɝɨɬɨɜɵɟ ɢɫɩɨɥɧɹɟɦɵɟ ɮɚɣɥɵ ɞɥɹ Windows, Linux, Solaris, HP-UX, AIX, QNX ɢ Mac OSX. Ȼɨɥɶɲɨɣ ɢɧɬɟɪɟɫ ɜ Eclipse ɩɪɟɞɫɬɚɜɥɹɟɬ plug-in ɚɪɯɢɬɟɤɬɭɪɚ, ɚ ɬɚɤɠɟ ɛɨɝɚɬɵɣ API, ɩɪɟɞɨɫɬɚɜɥɹɟɦɵɣ PDE, ɩɨɡɜɨɥɹɸɳɢɣ ɪɚɫɲɢɪɹɬɶ Eclipse. 1. ɍɫɬɚɧɨɜɤɚ ɢ ɡɚɩɭɫɤ Eclipse Eclipse – ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ ɫ ɨɬɤɪɵɬɵɦ ɤɨɞɨɦ, ɢɫɩɨɥɶɡɭɟɦɨɟ ɤɚɤ IDE – ɢɧɬɟɝɪɢɪɨɜɚɧɧɚɹ ɫɪɟɞɚ ɪɚɡɪɚɛɨɬɤɢ ɢ ɤɚɤ ɨɫɧɨɜɚ ɞɥɹ ɩɪɨɝɪɚɦɦɧɵɯ ɩɪɨɞɭɤɬɨɜ. ɉɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ ɦɨɠɟɬ ɛɵɬɶ ɜɵɝɪɭɠɟɧɨ ɫ ɫɚɣɬɚ http://www.eclipse.org/downloads.
4
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ȼ ɛɨɥɶɲɢɧɫɬɜɟ ɫɥɭɱɚɟɜ ɪɚɡɪɚɛɨɬɱɢɤɢ ɫɬɪɟɦɹɬɫɹ ɜɵɝɪɭɡɢɬɶ ɫɚɦɭɸ ɩɨɫɥɟɞɧɸɸ ɜɟɪɫɢɸ ɩɚɤɟɬɚ. ȼɵɛɟɪɢɬɟ ɩɚɤɟɬ ɢ ɩɥɚɬɮɨɪɦɭ, ɧɚ ɤɨɬɨɪɨɣ ɛɭɞɟɬ ɢɧɫɬɚɥɥɢɪɨɜɚɬɶ ɩɪɨɞɭɤɬ. ɋɨɯɪɚɧɢɬɟ ZIP-ɮɚɣɥ, ɫɨɞɟɪɠɚɳɢɣ ɩɨɥɧɨɟ ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ Eclipse ɧɚ ɥɨɤɚɥɶɧɨɦ ɞɢɫɤɟ. Ⱦɥɹ ɢɧɫɬɚɥɥɹɰɢɢ Eclipse ɧɟɨɛɯɨɞɢɦɨ ɪɚɫɩɚɤɨɜɚɬɶ ɜɵɝɪɭɠɟɧɧɵɣ ɮɚɣɥ. Ɋɚɫɩɚɤɨɜɤɚ ZIP-ɮɚɣɥɚ ɧɚ ɞɢɫɤ c:\ ɩɪɢɜɟɞɟɬ ɤ ɫɨɡɞɚɧɢɸ ɤɚɬɚɥɨɝɚ c:\eclipse, ɤɨɬɨɪɵɣ ɫɨɞɟɪɠɢɬ ɢɫɩɨɥɧɹɟɦɵɣ ɮɚɣɥ Eclipse (eclipse.exe). ɓɟɥɤɧɢɬɟ ɞɜɚɠɞɵ ɧɚ ɮɚɣɥɟ eclipse.exe, ɱɬɨɛɵ ɡɚɩɭɫɬɢɬɶ Eclipse. ɉɨɫɤɨɥɶɤɭ Eclipse ɧɚɩɢɫɚɧ ɧɚ Java, ɩɪɨɝɪɚɦɦɧɨɟ ɨɛɟɫɩɟɱɟɧɢɟ ɬɪɟɛɭɟɬ ɞɥɹ ɜɵɩɨɥɧɟɧɢɹ Java Runtime Environment (JRE) ɢɥɢ Java Development Kit (JDK) ɫ javaw.exe.
ȿɫɥɢ ɧɟ ɭɫɬɚɧɨɜɥɟɧ ɩɭɬɶ ɞɥɹ javaw.exe, ɩɨɹɜɢɬɫɹ ɨɤɧɨ ɫ ɫɨɨɛɳɟɧɢɟɦ ɨɛ ɨɬɫɭɬɫɬɜɢɢ JRE/JDK. ȼ ɬɚɤɨɦ ɫɥɭɱɚɟ ɭɫɬɚɧɨɜɢɬɟ ɩɟɪɟɦɟɧɧɭɸ ɨɤɪɭɠɟɧɢɹ JAVA_HOME, ɱɬɨɛɵ ɨɧɚ ɭɤɚɡɵɜɚɥɚ ɧɚ ɤɚɬɚɥɨɝ ɜɚɲɟɣ ɢɧɫɬɚɥɥɹɰɢɢ JDK. ȿɫɥɢ ɧɚ ɥɨɤɚɥɶɧɨɦ ɞɢɫɤɟ ɧɟɬ ɭɫɬɚɧɨɜɤɢ JDK ɢɥɢ JRE, ɦɨɠɧɨ ɜɵɝɪɭɡɢɬɶ JRE ɫ ɫɚɣɬɚ Eclipse – http://download.eclipse.org/eclipse/downloads/drops/R-3.2.2200702121330/.
ɉɨɫɥɟ ɭɫɬɚɧɨɜɤɢ ɧɚ ɥɨɤɚɥɶɧɨɦ ɞɢɫɤɟ JRE ɧɭɠɧɨ ɭɫɬɚɧɨɜɢɬɶ ɩɟɪɟɦɟɧɧɭɸ ɨɤɪɭɠɟɧɢɹ JAVA_HOME, ɟɫɥɢ ɷɬɨ ɟɳɟ ɧɟ ɫɞɟɥɚɧɨ.
5
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɉɨɫɥɟ ɭɫɬɚɧɨɜɤɢ JAVA_HOME ɫɧɨɜɚ ɞɜɚɠɞɵ ɳɟɥɤɧɢɬɟ ɧɚ ɮɚɣɥɟ eclipse.exe, ɢɧɫɬɚɥɥɹɰɢɹ ɛɭɞɟɬ ɡɚɜɟɪɲɟɧɚ ɩɪɢɝɥɚɲɟɧɢɟɦ ɫɨɡɞɚɬɶ ɤɚɬɚɥɨɝ ɪɚɛɨɱɟɝɨ ɩɪɨɫɬɪɚɧɫɬɜɚ c:\eclipse\workspace. Ʉɚɬɚɥɨɝ ɪɚɛɨɱɟɝɨ ɩɪɨɫɬɪɚɧɫɬɜɚ ɩɨ ɭɦɨɥɱɚɧɢɸ ɹɜɥɹɟɬɫɹ ɩɨɞɤɚɬɚɥɨɝɨɦ ɜ ɤɚɬɚɥɨɝɟ ɢɧɫɬɚɥɥɹɰɢɢ.
6
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ȼ ɤɨɧɟɱɧɨɦ ɢɬɨɝɟ ɩɨɹɜɢɬɫɹ Ɋɚɛɨɱɟɟ Ɇɟɫɬɨ – Workbench.
1.1. ɉɪɨɜɟɪɤɚ ɢɧɫɬɚɥɥɹɰɢɢ JRE ɢ ɩɟɪɟɦɟɧɧɵɯ CLASSPATH 1. ȼɵɛɟɪɢɬɟ ɩɭɧɤɬ ɦɟɧɸ Window > Preferences, ɱɬɨɛɵ ɨɬɤɪɵɬɶ ɧɚɫɬɪɨɣɤɢ ɪɚɛɨɱɟɝɨ ɦɟɫɬɚ. 2. ȼɵɛɟɪɢɬɟ Java > Installed JREs ɜ ɩɚɧɟɥɢ ɞɟɪɟɜɚ ɫɥɟɜɚ, ɱɬɨɛɵ ɨɬɨɛɪɚɡɢɬɶ ɫɬɪɚɧɢɰɭ Installed Java Runtime Environments. ɍɛɟɞɢɬɟɫɶ, ɱɬɨ JRE ɨɛɧɚɪɭɠɟɧɚ. ɉɨ ɭɦɨɥɱɚɧɢɸ JRE, ɢɫɩɨɥɶɡɭɟɦɚɹ ɞɥɹ ɜɵɩɨɥɧɟɧɢɹ ɪɚɛɨɱɟɝɨ ɦɟɫɬɚ, ɛɭɞɟɬ ɢɫɩɨɥɶɡɨɜɚɧɚ ɞɥɹ ɩɨɫɬɪɨɟɧɢɹ ɢ ɜɵɩɨɥɧɟɧɢɹ Java-ɩɪɨɝɪɚɦɦ. Ɉɧɚ ɞɨɥɠɧɚ ɩɨɹɜɢɬɶɫɹ ɫ ɦɚɪɤɟɪɨɦ ɨɬɦɟɬɤɢ ɜ ɫɩɢɫɤɟ ɢɧɫɬɚɥɥɢɪɨɜɚɧɧɵɯ JRE. Ɋɟɤɨɦɟɧɞɭɟɬɫɹ ɢɫɩɨɥɶɡɨɜɚɬɶ Java SDK ɜɦɟɫɬɨ JRE. SDK ɫɩɪɨɟɤɬɢɪɨɜɚɧ ɞɥɹ ɪɚɡɪɚɛɨɬɤɢ ɢ ɫɨɞɟɪɠɢɬ ɢɫɯɨɞɧɵɣ ɤɨɞ ɛɢɛɥɢɨɬɟɤɢ Java, ɩɨɷɬɨɦɭ ɨɛɥɟɝɱɚɟɬ ɨɬɥɚɞɤɭ. Ⱦɨɩɨɥɧɢɬɟɥɶɧɵɟ SDK ɦɨɝɭɬ ɛɵɬɶ ɞɨɛɚɜɥɟɧɵ ɩɭɬɟɦ ɩɨɢɫɤɚ ɧɚ ɞɢɫɤɟ ɢɧɫɬɚɥɥɢɪɨɜɚɧɧɵɯ SDK. ɑɬɨɛɵ ɫɞɟɥɚɬɶ ɷɬɨ, ɩɪɨɫɬɨ ɳɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Search ɢ ɡɚɞɚɣɬɟ ɤɨɪɧɟɜɨɣ ɤɚɬɚɥɨɝ ɞɥɹ ɩɨɢɫɤɚ.
7
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
3. ȼɵɛɟɪɢɬɟ General>Workspace ɜ ɩɚɧɟɥɢ ɞɟɪɟɜɚ, ɱɬɨɛɵ ɨɬɨɛɪɚɡɢɬɶ ɫɬɪɚɧɢɰɭ ɧɚɫɬɪɨɟɤ Workspace. ɍɛɟɞɢɬɟɫɶ, ɱɬɨ ɨɩɰɢɹ Build automatically ɜɵɛɪɚɧɚ.
4. ȼɵɛɟɪɢɬɟ Java > Build Path ɜ ɩɚɧɟɥɢ ɞɟɪɟɜɚ, ɱɬɨɛɵ ɨɬɨɛɪɚɡɢɬɶ ɫɬɪɚɧɢɰɭ ɧɚɫɬɪɨɟɤ Build Path. ɍɛɟɞɢɬɟɫɶ, ɱɬɨ ɜ Source and output folder ɜɵɛɪɚɧɨ Project.
8
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
5. ɓɟɥɤɧɢɬɟ ɧɚ OK, ɱɬɨɛɵ ɫɨɯɪɚɧɢɬɶ ɧɚɫɬɪɨɣɤɢ. 2. ɋɨɡɞɚɧɢɟ ɩɟɪɜɨɝɨ ɩɪɨɟɤɬɚ Java ɉɪɢ ɫɨɡɞɚɧɢɢ ɩɪɨɟɤɬɚ ɛɭɞɟɦ ɢɫɩɨɥɶɡɨɜɚɬɶ JUnit ɜ ɤɚɱɟɫɬɜɟ ɩɪɨɟɤɬɚɩɪɢɦɟɪɚ. JUnit – ɦɨɞɭɥɶ ɫ ɨɬɤɪɵɬɵɦ ɤɨɞɨɦ ɞɥɹ ɬɟɫɬɢɪɨɜɚɧɢɹ ɤɚɪɤɚɫɚ ɞɥɹ Java. 2.1. ɉɨɥɭɱɟɧɢɟ ɤɨɞɚ ɩɪɢɦɟɪɚ (JUnit) ɋɧɚɱɚɥɚ ɧɭɠɧɨ ɜɵɝɪɭɡɢɬɶ ɢɫɯɨɞɧɵɣ ɤɨɞ JUnit. 1. Ɂɚɣɞɢɬɟ ɧɚ ɫɬɪɚɧɢɰɭ http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jdt.ui.examples.projects/arc hive/junit/ . 2. ȼɵɝɪɭɡɢɬɟ ɚɪɯɢɜ ɩɪɢɦɟɪɚ junit381src.jar.
3. Ɋɚɫɩɚɤɭɣɬɟ ɫɨɞɟɪɠɢɦɨɟ Zip-ɮɚɣɥɚ ɜ ɤɚɬɚɥɨɝ, ɧɚ ɤɨɬɨɪɵɣ ɦɵ ɛɭɞɟɦ ɫɫɵɥɚɬɶɫɹ (ɧɚɩɪɢɦɟɪ, ɋ:\Downloads). 2.2. ɋɨɡɞɚɧɢɟ ɩɪɨɟɤɬɚ 1. ȼ Eclipse ɜɵɛɟɪɢɬɟ ɩɭɧɤɬ ɦɟɧɸ File > New > Project..., ɱɬɨɛɵ ɨɬɤɪɵɬɶ Ɇɚɫɬɟɪ New Project. 2. ȼɵɛɟɪɢɬɟ Java Project ɢ ɳɟɥɤɧɢɬɟ ɧɚ Next. ɇɚ ɫɥɟɞɭɸɳɟɣ ɫɬɪɚɧɢɰɟ ɜɜɟɞɢɬɟ Junit ɜ ɩɨɥɟ Project name ɢ ɳɟɥɤɧɢɬɟ ɧɚ Finish. ɇɚ ɧɚɱɚɥɶɧɨɣ ɫɬɪɚɧɢɰɟ Welcome ɳɟɥɤɧɢɬɟ ɩɨ ɡɧɚɱɤɭ Workbench. ȼ ɪɚɛɨɱɟɦ ɦɟɫɬɟ ɨɬɤɪɨɟɬɫɹ ɩɟɪɫɩɟɤɬɢɜɚ Java ɫ ɧɨɜɵɦ ɩɪɨɟɤɬɨɦ Java ɜ Package Explorer. Ʉɨɝɞɚ ɩɟɪɫɩɟɤɬɢɜɚ Java ɚɤɬɢɜɧɚ, ɜ ɩɚɧɟɥɶ ɢɧɫɬɪɭɦɟɧɬɨɜ ɪɚɛɨɱɟɝɨ ɦɟɫɬɚ ɡɚɝɪɭɠɚɸɬɫɹ ɧɨɜɵɟ ɨɩɰɢɢ ɦɟɧɸ ɢ 9
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɫɩɟɰɢɮɢɱɧɵɟ ɞɥɹ Java ɤɧɨɩɤɢ. ȼ ɡɚɜɢɫɢɦɨɫɬɢ ɨɬ ɬɨɝɨ, ɤɚɤɨɣ ɪɟɞɚɤɬɨɪ ɚɤɬɢɜɟɧ, ɛɭɞɭɬ ɞɨɫɬɭɩɧɵ ɞɪɭɝɢɟ ɨɩɰɢɢ ɢ ɤɧɨɩɤɢ.
3. ȼ Package Explorer ɭɛɟɞɢɬɟɫɶ, ɱɬɨ ɜɵɛɪɚɧ ɩɪɨɟɤɬ JUnit. ȼɵɛɟɪɢɬɟ ɩɭɧɤɬ ɦɟɧɸ File > Import... . 4. ȼɵɛɟɪɢɬɟ General>Archive File ɢ ɳɟɥɤɧɢɬɟ ɧɚ Next. 5. ɓɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Browse ɡɚ ɩɨɥɟɦ From archive file ɢ ɧɚɣɞɢɬɟ ɞɥɹ ɜɵɛɨɪɚ junit381src.jar. ɉɪɢɦɟɱɚɧɢɟ: ɗɬɨɬ ɲɚɝ ɩɪɟɞɩɨɥɚɝɚɟɬ, ɱɬɨ ɜɵɩɨɥɧɟɧɵ ɲɚɝɢ 1-3 ɜ ɩɪɟɞɵɞɭɳɟɦ ɪɚɡɞɟɥɟ. 6. ȼ Ɇɚɫɬɟɪɟ Import ɩɨɞ ɫɩɢɫɤɨɦ ɢɟɪɚɪɯɢɢ ɳɟɥɤɧɢɬɟ ɧɚ Select All. Ɇɨɠɧɨ ɪɚɫɤɪɵɬɶ ɢ ɜɵɛɪɚɬɶ ɷɥɟɦɟɧɬɵ ɜ ɤɚɬɚɥɨɝɟ junit ɧɚ ɥɟɜɨɣ ɩɚɧɟɥɢ, ɱɬɨɛɵ ɩɪɨɫɦɨɬɪɟɬɶ ɨɬɞɟɥɶɧɵɟ ɪɟɫɭɪɫɵ, ɤɨɬɨɪɵɟ ɛɵɥɢ ɢɦɩɨɪɬɢɪɨɜɚɧɵ, ɧɚ ɩɪɚɜɨɣ ɩɚɧɟɥɢ. ɉɪɢɦɟɱɚɧɢɟ: ɇɟ ɨɬɦɟɧɹɣɬɟ ɩɪɢ ɷɬɨɦ ɜɵɛɨɪ ɧɢɤɚɤɢɯ ɪɟɫɭɪɫɨɜ ɜ ɤɚɬɚɥɨɝɟ junit. ȼɚɦ ɩɨɧɚɞɨɛɹɬɫɹ ɜɫɟ ɷɬɢ ɪɟɫɭɪɫɵ.
10
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
7. ɍɛɟɞɢɬɟɫɶ, ɱɬɨ ɩɪɨɟɤɬ JUnit ɩɨɹɜɢɥɫɹ ɜ ɩɨɥɟ Folder. Ɂɚɬɟɦ ɳɟɥɤɧɢɬɟ ɧɚ Finish. ȼ ɢɧɞɢɤɚɬɨɪɟ ɯɨɞɚ ɜɵɩɨɥɧɟɧɢɹ ɢɦɩɨɪɬɚ ɡɚɦɟɬɶɬɟ, ɱɬɨ ɢɦɩɨɪɬɢɪɭɟɦɵɟ ɪɟɫɭɪɫɵ ɤɨɦɩɢɥɢɪɭɸɬɫɹ ɩɨ ɦɟɪɟ ɬɨɝɨ, ɤɚɤ ɨɧɢ ɢɦɩɨɪɬɢɪɭɸɬɫɹ ɜ ɪɚɛɨɱɟɟ ɦɟɫɬɨ. ɗɬɨ ɩɨɬɨɦɭ, ɱɬɨ ɧɚ ɫɬɪɚɧɢɰɟ ɧɚɫɬɪɨɟɤ Workbench ɜɵɛɪɚɧɚ ɨɩɰɢɹ Build automatically. Ⱦɚɥɟɟ ɩɨɥɭɱɢɬɟ ɩɪɢɝɥɚɲɟɧɢɟ ɩɟɪɟɡɚɩɢɫɚɬɶ ɮɚɣɥɵ .classpath ɢ .project ɜ ɩɪɨɟɤɬɟ JUnit. ɗɬɨ ɩɨɬɨɦɭ, ɱɬɨ ɪɟɫɭɪɫ .classpath ɛɵɥ ɫɨɡɞɚɧ, ɤɨɝɞɚ ɫɨɡɞɚɜɚɥɫɹ ɩɪɨɟɤɬ JUnit. Ɇɨɠɧɨ ɩɟɪɟɡɚɩɢɫɚɬɶ ɷɬɢ ɮɚɣɥɵ. 8. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɪɚɫɤɪɨɣɬɟ ɩɪɨɟɤɬ JUnit, ɱɬɨɛɵ ɩɨɫɦɨɬɪɟɬɶ ɩɚɤɟɬɵ JUnit.
11
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
2.3. ɉɪɨɫɦɨɬɪ ɷɥɟɦɟɧɬɨɜ Java ɩɪɢ ɩɨɦɨɳɢ Package Explorer ɂɫɫɥɟɞɭɟɦ ɷɥɟɦɟɧɬɵ Java ɜ ɩɪɨɟɤɬɟ JUnit. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɪɚɫɤɪɨɣɬɟ ɩɪɨɟɤɬ JUnit, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɟɝɨ ɩɚɤɟɬɵ. 1. Ɋɚɫɤɪɨɣɬɟ ɩɚɤɟɬ junit.framework, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɮɚɣɥɵ Java, ɫɨɞɟɪɠɚɳɢɟɫɹ ɜ ɩɚɤɟɬɟ. 2. Ɋɚɫɤɪɨɣɬɟ ɮɚɣɥ TestCase.java. Ɂɚɦɟɬɶɬɟ, ɱɬɨ Package Explorer ɩɨɤɚɡɵɜɚɟɬ ɫɩɟɰɢɮɢɱɧɵɟ ɞɥɹ Java ɩɨɞɷɥɟɦɟɧɬɵ ɜ ɢɫɯɨɞɧɨɦ ɤɨɞɟ ɮɚɣɥɚ. ȼɚɠɧɵɟ ɨɛɴɹɜɥɟɧɢɹ, ɨɬɤɪɵɬɵɟ ɬɢɩɵ ɢ ɢɯ ɱɥɟɧɵ (ɩɨɥɹ ɢ ɦɟɬɨɞɵ) ɩɨɹɜɥɹɸɬɫɹ ɜ ɞɟɪɟɜɟ.
12
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
3. Ɋɟɞɚɤɬɢɪɨɜɚɧɢɟ ɷɥɟɦɟɧɬɨɜ Java 3.1. Ɉɬɤɪɵɬɢɟ ɪɟɞɚɤɬɨɪɚ Java Ⱦɥɹ ɬɨɝɨ ɱɬɨɛɵ ɨɬɤɪɵɬɶ ɪɟɞɚɤɬɨɪ ɞɥɹ ɮɚɣɥɨɜ Java, ɧɟɨɛɯɨɞɢɦɨ ɜɵɩɨɥɧɢɬɶ ɫɥɟɞɭɸɳɢɟ ɞɟɣɫɬɜɢɹ: 1. Ɋɚɫɤɪɨɣɬɟ ɩɚɤɟɬ junit.samples ɢ ɜɵɛɟɪɢɬɟ ɮɚɣɥ VectorTest.java. Ɇɨɠɧɨ ɨɬɤɪɵɬɶ VectorTest.java ɜ ɪɟɞɚɤɬɨɪɟ Java, ɞɜɚɠɞɵ ɳɟɥɤɧɭɜ ɧɚ ɧɟɦ. ȼɨɨɛɳɟ ɦɨɠɧɨ ɨɬɤɪɵɜɚɬɶ ɜ ɪɟɞɚɤɬɨɪɟ Java ɮɚɣɥɵ, ɬɢɩɵ, ɦɟɬɨɞɵ ɢ ɩɨɥɹ ɩɪɨɫɬɨ ɞɜɚɠɞɵ ɳɟɥɤɚɹ ɧɚ ɧɢɯ. ɇɚɩɪɢɦɟɪ, ɦɨɠɧɨ ɨɬɤɪɵɬɶ ɪɟɞɚɤɬɨɪ ɧɟɩɨɫɪɟɞɫɬɜɟɧɧɨ ɧɚ ɦɟɬɨɞɟ testClone(), ɨɩɪɟɞɟɥɟɧɧɨɦ ɜ VectorTest.java, ɞɜɚɠɞɵ ɳɟɥɤɧɭɜ ɧɚ ɧɟɦ ɜ Package Explorer. 2. Ɉɬɦɟɬɶɬɟ ɜɵɞɟɥɟɧɢɟ ɫɢɧɬɚɤɫɢɫɚ. Ɋɚɡɧɵɟ ɜɢɞɵ ɷɥɟɦɟɧɬɨɜ ɜ ɢɫɯɨɞɧɨɦ ɤɨɞɟ Java ɢɡɨɛɪɚɠɚɸɬɫɹ ɪɚɡɧɵɦɢ ɰɜɟɬɚɦɢ. ɉɪɢɦɟɪɚɦɢ ɷɥɟɦɟɧɬɨɜ ɢɫɯɨɞɧɨɝɨ ɤɨɞɚ Java, ɢɡɨɛɪɚɠɚɟɦɵɯ ɩɨ-ɪɚɡɧɨɦɭ, ɹɜɥɹɸɬɫɹ: o Ɉɛɵɱɧɵɟ ɤɨɦɦɟɧɬɚɪɢɢ o Ʉɨɦɦɟɧɬɚɪɢɢ Javadoc o Ʉɥɸɱɟɜɵɟ ɫɥɨɜɚ o ɋɬɪɨɤɢ.
13
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɉɨɫɦɨɬɪɢɬɟ ɧɚ ɩɪɟɞɫɬɚɜɥɟɧɢɟ Outline, ɪɚɫɩɨɥɨɠɟɧɧɨɟ ɫɩɪɚɜɚ. Ɉɧɨ ɨɬɨɛɪɚɠɚɟɬ ɫɯɟɦɭ ɮɚɣɥɨɜ Java, ɜɤɥɸɱɚɹ ɨɛɴɹɜɥɟɧɢɟ ɩɚɤɟɬɚ, ɨɛɴɹɜɥɟɧɢɟ ɢɦɩɨɪɬɚ, ɩɨɥɹ, ɬɢɩɵ ɢ ɦɟɬɨɞɵ. ɉɪɟɞɫɬɚɜɥɟɧɢɟ Outline ɢɫɩɨɥɶɡɭɟɬ ɢɤɨɧɤɢ ɞɥɹ ɨɩɢɫɚɧɢɹ ɷɥɟɦɟɧɬɨɜ Java. ɇɚɩɪɢɦɟɪ, ɢɤɨɧɤɚ, ɩɨɤɚɡɵɜɚɸɳɚɹ, ɹɜɥɹɟɬɫɹ ɥɢ ɷɥɟɦɟɧɬ Java ɫɬɚɬɢɱɟɫɤɢɦ, ɚɛɫɬɪɚɤɬɧɵɦ ɢɥɢ ɮɢɧɚɥɶɧɵɦ. Ɋɚɡɧɵɟ ɢɤɨɧɤɢ ɩɨɤɚɡɵɜɚɸɬ, ɩɟɪɟɤɪɵɜɚɟɬ ɥɢ ɦɟɬɨɞ ɛɚɡɨɜɨɝɨ ɤɥɚɫɫɚ ( ) ɢɥɢ ɪɟɚɥɢɡɭɟɬ ɦɟɬɨɞ ɢɧɬɟɪɮɟɣɫɚ ( ). 3. ɉɟɪɟɤɥɸɱɚɣɬɟ ɤɧɨɩɤɢ Hide Fields, Hide Static Fields and Metholds ɢ Hide Non-Public Members ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Outline, ɱɬɨɛɵ ɮɢɥɶɬɪɨɜɚɬɶ ɬɨ, ɱɬɨ ɨɬɨɛɪɚɠɚɟɬɫɹ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ. ɉɟɪɟɞ ɩɟɪɟɯɨɞɨɦ ɤ ɫɥɟɞɭɸɳɟɦɭ ɲɚɝɭ ɭɛɟɞɢɬɟɫɶ, ɱɬɨ ɤɧɨɩɤɚ Hide Non-Public Members ɧɟ ɧɚɠɚɬɚ. 4. Ɇɨɠɧɨ ɪɟɞɚɤɬɢɪɨɜɚɬɶ ɢɫɯɨɞɧɵɣ ɤɨɞ, ɩɪɨɫɦɚɬɪɢɜɚɹ ɜɟɫɶ ɮɚɣɥ Java, ɢɥɢ ɨɝɪɚɧɢɱɢɬɶ ɩɪɟɞɫɬɚɜɥɟɧɢɟ ɟɞɢɧɫɬɜɟɧɧɵɦ ɷɥɟɦɟɧɬɨɦ Java. ɉɚɧɟɥɶ ɢɧɫɬɪɭɦɟɧɬɨɜ ɜɤɥɸɱɚɟɬ ɜ ɫɟɛɹ ɤɧɨɩɤɭ Show Source of Selected Element Only, ɱɬɨ ɩɪɢɜɟɞɟɬ ɤ ɬɨɦɭ, ɱɬɨ ɜ ɪɟɞɚɤɬɨɪɟ Java ɛɭɞɟɬ ɨɬɨɛɪɚɠɚɬɶɫɹ ɢɫɯɨɞɧɵɣ ɤɨɞ ɬɨɥɶɤɨ ɜɵɛɪɚɧɧɨɝɨ ɧɚ ɫɯɟɦɟ ɷɥɟɦɟɧɬɚ. ȼ ɩɪɢɦɟɪɟ ɧɢɠɟ ɨɬɨɛɪɚɠɚɟɬɫɹ ɬɨɥɶɤɨ ɦɟɬɨɞ setUp().
14
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
5. ɋɧɨɜɚ ɧɚɠɦɢɬɟ ɧɚ ɤɧɨɩɤɭ Show Source of Selected Element Only, ɱɬɨɛɵ ɨɩɹɬɶ ɭɜɢɞɟɬɶ ɜɟɫɶ ɮɚɣɥ Java. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline ɜɵɛɢɪɚɣɬɟ ɪɚɡɧɵɟ ɷɥɟɦɟɧɬɵ ɢ ɡɚɦɟɱɚɣɬɟ, ɱɬɨ ɨɧɢ ɨɩɹɬɶ ɨɬɨɛɪɚɠɚɸɬɫɹ ɜ ɩɨɥɧɨɦ ɩɪɟɞɫɬɚɜɥɟɧɢɢ ɮɚɥɚ ɜ ɪɟɞɚɤɬɨɪɟ. ɉɪɟɞɫɬɚɜɥɟɧɢɟ Outline ɬɟɩɟɪɶ ɫɨɞɟɪɠɢɬ ɢɧɞɢɤɚɬɨɪ ɝɪɚɧɢɰ ɧɚ ɜɟɪɬɢɤɚɥɶɧɨɣ ɥɢɧɟɣɤɟ ɩɨ ɥɟɜɨɣ ɝɪɚɧɢɰɟ ɪɟɞɚɤɬɨɪɚ Java, ɤɨɬɨɪɵɣ ɩɨɤɚɡɵɜɚɟɬ ɝɪɚɧɢɰɵ ɜɵɛɪɚɧɧɨɝɨ ɷɥɟɦɟɧɬɚ.
3.2. Ⱦɨɛɚɜɥɟɧɢɟ ɧɨɜɵɯ ɦɟɬɨɞɨɜ 1. ɇɚɱɧɢɬɟ ɞɨɛɚɜɥɟɧɢɟ ɦɟɬɨɞɚ ɫ ɧɚɩɢɫɚɧɢɹ ɫɥɟɞɭɸɳɟɝɨ ɜ ɤɨɧɰɟ ɮɚɣɥɚ VectorTest.java (ɧɨ ɞɨ ɡɚɤɪɵɜɚɸɳɟɣ ɮɢɝɭɪɧɨɣ ɫɤɨɛɤɢ ɬɢɩɚ) ɜ ɪɟɞɚɤɬɨɪɟ Java: 15
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
public void testSizeIsThree()
Ʉɚɤ ɬɨɥɶɤɨ ɛɭɞɟɬ ɧɚɩɟɱɚɬɚɧɨ ɢɦɹ ɦɟɬɨɞɚ ɜ ɨɛɥɚɫɬɢ ɪɟɞɚɤɬɨɪɚ, ɧɨɜɵɣ ɦɟɬɨɞ ɩɨɹɜɢɬɫɹ ɜɧɢɡɭ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline. Ʉɪɨɦɟ ɬɨɝɨ, ɡɚɦɟɬɤɚ ɨɛ ɨɲɢɛɤɟ (ɤɪɚɫɧɵɣ ɩɪɹɦɨɭɝɨɥɶɧɢɤ) ɩɨɹɜɥɹɟɬɫɹ ɧɚ ɥɢɧɟɣɤɟ ɫɩɪɚɜɚ ɨɬ ɪɟɞɚɤɬɨɪɚ. ɗɬɚ ɡɚɦɟɬɤɚ ɨɛ ɨɲɢɛɤɟ ɩɨɤɚɡɵɜɚɟɬ, ɱɬɨ ɦɨɞɭɥɶ ɜ ɞɚɧɧɵɣ ɦɨɦɟɧɬ ɧɟɩɪɚɜɢɥɶɧɵɣ. ȿɫɥɢ ɩɨɦɟɫɬɢɬɶ ɤɭɪɫɨɪ ɧɚɞ ɤɪɚɫɧɵɦ ɤɜɚɞɪɚɬɢɤɨɦ, ɩɨɹɜɢɬɫɹ ɩɨɞɫɤɚɡɤɚ Syntax error on token ")", "{" expected, after this token, ɤɨɬɨɪɚɹ ɩɪɚɜɢɥɶɧɚɹ, ɩɨɫɤɨɥɶɤɭ ɩɨɤɚ ɦɟɬɨɞ ɧɟ ɢɦɟɟɬ ɟɳɟ ɬɟɥɚ.
2. ɓɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Save. Ɇɨɞɭɥɶ ɤɨɦɩɢɥɢɪɭɟɬɫɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɢ ɩɨɹɜɥɹɟɬɫɹ ɨɲɢɛɤɚ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer, ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Problems ɢ ɧɚ ɜɟɪɬɢɤɚɥɶɧɨɣ ɥɢɧɟɣɤɟ (ɩɨ ɥɟɜɭɸ ɫɬɨɪɨɧɭ ɪɟɞɚɤɬɨɪɚ). ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɨɲɢɛɤɢ ɪɚɫɩɪɨɫɬɪɚɧɹɸɬɫɹ ɨɬ ɦɨɞɭɥɹ, ɫɨɞɟɪɠɚɳɟɝɨ ɨɲɢɛɤɭ ɧɚ ɩɪɨɟɤɬ.
16
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
3. Ɂɚɤɨɧɱɢɬɟ ɧɨɜɵɣ ɦɟɬɨɞ, ɧɚɩɟɱɚɬɚɜ ɫɥɟɞɭɸɳɟɟ: {
assertTrue(fFull.size()==3);
Ɂɚɤɪɵɜɚɸɳɚɹ ɮɢɝɭɪɧɚɹ ɫɤɨɛɤɚ ɞɨɥɠɧɚ ɜɫɬɚɜɢɬɶɫɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ. 4. ɋɨɯɪɚɧɢɬɟ ɮɚɣɥ. Ɂɚɦɟɬɶɬɟ, ɱɬɨ ɨɬɦɟɬɤɚ ɨɛ ɨɲɢɛɤɟ ɩɪɨɩɚɞɟɬ, ɤɨɝɞɚ ɛɭɞɟɬ ɞɨɛɚɜɥɟɧɚ ɨɬɫɭɬɫɬɜɭɸɳɚɹ ɮɢɝɭɪɧɚɹ ɫɤɨɛɤɚ. 3.3. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɤɨɧɬɟɧɬɧɨɣ ɩɨɦɨɳɢ Ⱦɚɥɟɟ ɛɭɞɟɦ ɢɫɩɨɥɶɡɨɜɚɬɶ ɤɨɧɬɟɧɬɧɭɸ ɩɨɦɨɳɶ, ɱɬɨɛɵ ɡɚɤɨɧɱɢɬɶ ɧɚɩɢɫɚɧɢɟ ɧɨɜɨɝɨ ɦɟɬɨɞɚ. Ɉɬɤɪɨɣɬɟ ɮɚɣɥ junit.samples.VectorTest.java ɜ ɪɟɞɚɤɬɨɪɟ Java, ɟɫɥɢ ɨɧ ɭ ɜɚɫ ɟɳɟ ɧɟ ɨɬɤɪɵɬ, ɢ ɜɵɛɟɪɢɬɟ ɦɟɬɨɞ testSizeIsThree() ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline. ȿɫɥɢ ɮɚɣɥ ɟɳɟ ɧɟ ɫɨɞɟɪɠɢɬ ɬɚɤɨɝɨ ɦɟɬɨɞɚ, ɞɨɛɚɜɶɬɟ ɟɝɨ, ɤɚɤ ɷɬɨ ɛɵɥɨ ɫɞɟɥɚɧɨ ɜɵɲɟ. 1. Ⱦɨɛɚɜɶɬɟ ɫɥɟɞɭɸɳɢɟ ɫɬɪɨɤɢ ɜ ɤɨɧɟɰ ɦɟɬɨɞɚ: Vector v = new Vector(); for (int i=0; i<3; i++) v.addElement(new Object()); assert 2. Ʉɨɝɞɚ ɤɭɪɫɨɪ ɛɭɞɟɬ ɜ ɤɨɧɰɟ ɫɥɨɜɚ assert, ɧɚɠɦɢɬɟ Ctrl+Space,
ɱɬɨɛɵ ɚɤɬɢɜɢɡɢɪɨɜɚɬɶ ɤɨɧɬɟɧɬɧɭɸ ɩɨɦɨɳɶ. ɉɨɹɜɢɬɫɹ ɨɤɧɨ ɤɨɧɬɟɧɬɧɨɣ ɩɨɦɨɳɢ ɫɨ ɫɩɢɫɤɨɦ ɩɪɟɞɥɨɠɟɧɢɣ. ɉɪɨɤɪɭɬɢɬɟ ɫɩɢɫɨɤ, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɜɨɡɦɨɠɧɵɟ ɜɚɪɢɚɧɬɵ. 17
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
3. ɋɨ ɜɫɟ ɟɳɟ ɚɤɬɢɜɧɵɦ ɨɤɧɨɦ ɤɨɧɬɟɧɬɧɨɣ ɩɨɦɨɳɢ ɧɚɩɟɱɚɬɚɣɬɟ ɛɭɤɜɭ t ɜ ɢɫɯɨɞɧɨɦ ɤɨɞɟ ɩɨɫɥɟ assert (ɛɟɡ ɩɪɨɛɟɥɚ). ɋɩɢɫɨɤ ɭɦɟɧɶɲɢɬɫɹ ɢ ɛɭɞɟɬ ɩɨɤɚɡɵɜɚɬɶ ɬɨɥɶɤɨ ɷɥɟɦɟɧɬɵ, ɧɚɱɢɧɚɸɳɢɟɫɹ ɫ assertt. ɉɪɨɣɞɢɬɟ ɤɭɪɫɨɪɨɦ ɧɚɞ ɤɚɠɞɵɦ ɢɡ ɷɥɟɦɟɧɬɨɜ ɜ ɫɩɢɫɤɟ, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɢɦɟɸɳɭɸɫɹ ɜ Javadoc ɩɨɞɫɤɚɡɤɭ ɩɨ ɧɢɦ.
4. ȼɵɛɟɪɢɬɟ assertTrue(boolean) ɢɡ ɫɩɢɫɤɚ ɢ ɧɚɠɦɢɬɟ Enter. ȼɫɬɚɜɢɬɫɹ ɤɨɞ ɞɥɹ ɦɟɬɨɞɚ assertTrue(boolean). 5. Ɂɚɤɨɧɱɢɬɟ ɦɟɬɨɞ, ɱɬɨɛɵ ɨɧ ɱɢɬɚɥɫɹ ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ: assertTrue(v.size()==fFull.size());
6. ɋɨɯɪɚɧɢɬɟ ɮɚɣɥ. 3.4. ȼɵɹɜɥɟɧɢɟ ɨɲɢɛɨɤ ɜ ɤɨɞɟ Ⱦɚɥɟɟ ɪɚɫɫɦɨɬɪɢɦ ɪɚɡɥɢɱɧɵɟ ɢɧɞɢɤɚɬɨɪɵ, ɤɨɬɨɪɵɟ ɩɨɤɚɡɵɜɚɸɬ ɩɪɨɛɥɟɦɵ ɜ ɤɨɞɟ. ɉɪɨɛɥɟɦɵ ɩɨɫɬɪɨɟɧɢɹ ɨɬɨɛɪɚɠɚɸɬɫɹ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Problems ɢ ɨɬɦɟɱɚɸɬɫɹ ɧɚ ɜɟɪɬɢɤɚɥɶɧɨɣ ɥɢɧɟɣɤɟ ɜ ɢɫɯɨɞɧɨɦ ɤɨɞɟ. 1. Ɉɬɤɪɨɣɬɟ junit.framework.TestCase.java ɜ ɪɟɞɚɤɬɨɪɟ ɢɡ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Package Explorer. 2. ȼɧɟɫɢɬɟ ɫɢɧɬɚɤɫɢɱɟɫɤɭɸ ɨɲɢɛɤɭ ɭɞɚɥɟɧɢɟɦ ɬɨɱɤɢ ɫ ɡɚɩɹɬɨɣ ɜ ɤɨɧɰɟ ɨɛɴɹɜɥɟɧɢɹ ɩɚɤɟɬɚ ɜ ɢɫɯɨɞɧɨɦ ɤɨɞɟ.
3. ɓɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Save. ɉɪɨɟɤɬ ɛɭɞɟɬ ɩɟɪɟɫɬɪɨɟɧ, ɢ ɩɪɨɛɥɟɦɚ ɛɭɞɟɬ ɩɨɤɚɡɚɧɚ ɧɟɫɤɨɥɶɤɢɦɢ ɫɩɨɫɨɛɚɦɢ: x ȼ ɩɟɪɫɩɟɤɬɢɜɟ Problems ɩɟɪɟɱɢɫɥɹɸɬɫɹ ɩɪɨɛɥɟɦɵ. x ȼ ɩɟɪɫɩɟɤɬɢɜɟ Package Explorer, ɩɟɪɫɩɟɤɬɢɜɟType Hierarchy ɢɥɢ Outline ɨɬɦɟɬɤɢ ɨɛ ɨɲɢɛɤɚɯ ɩɨɹɜɥɹɸɬɫɹ ɧɚ ɨɲɢɛɨɱɧɵɯ ɷɥɟɦɟɧɬɚɯ Java ɢ ɧɚ ɢɯ ɪɨɞɢɬɟɥɶɫɤɢɯ ɷɥɟɦɟɧɬɚɯ. x ɇɚ ɜɟɪɬɢɤɚɥɶɧɨɣ ɥɢɧɟɣɤɟ ɪɟɞɚɤɬɨɪɚ ɨɬɦɟɬɤɚ ɨɲɢɛɤɢ ɨɬɨɛɪɚɠɚɟɬɫɹ ɜɨɡɥɟ ɨɲɢɛɨɱɧɨɣ ɫɬɪɨɤɢ. 18
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
x ȼɨɥɧɢɫɬɚɹ ɱɟɪɬɚ ɩɨɹɜɥɹɟɬɫɹ ɩɨɞ ɫɥɨɜɨɦ, ɤɨɬɨɪɨɟ ɦɨɠɟɬ ɫɨɞɟɪɠɚɬɶ ɨɲɢɛɤɟ. x Ɂɚɤɥɚɞɤɢ ɪɟɞɚɤɬɨɪɚ ɩɨɦɟɱɚɸɬɫɹ ɨɬɦɟɬɤɨɣ ɨɛ ɨɲɢɛɤɟ.
4. Ɇɨɠɧɨ ɩɨɦɟɫɬɢɬɶ ɤɭɪɫɨɪ ɧɚɞ ɨɬɦɟɬɤɨɣ ɨɛ ɨɲɢɛɤɟ ɧɚ ɜɟɪɬɢɤɚɥɶɧɨɣ ɥɢɧɟɣɤɟ, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɨɛɴɹɫɧɟɧɢɟ ɩɪɨɛɥɟɦɵ.
5. ɓɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Close ɧɚ ɡɚɤɥɚɞɤɟ ɪɟɞɚɤɬɨɪɚ, ɱɬɨɛɵ ɡɚɤɪɵɬɶ ɪɟɞɚɤɬɨɪ. 6. ȼ ɩɟɪɫɩɟɤɬɢɜɟ Problems ɜɵɛɟɪɢɬɟ ɩɪɨɛɥɟɦɭ ɢɡ ɫɩɢɫɤɚ. Ɉɬɤɪɨɣɬɟ ɤɨɧɬɟɤɫɬɧɨɟ ɦɟɧɸ ɢ ɜɵɛɟɪɢɬɟ Go To. Ɏɚɣɥ ɨɬɤɪɵɜɚɟɬɫɹ ɜ ɪɟɞɚɤɬɨɪɟ ɧɚ ɬɨɦ ɦɟɫɬɟ, ɝɞɟ ɨɛɧɚɪɭɠɟɧɚ ɩɪɨɛɥɟɦɚ.
7. ɂɫɩɪɚɜɶɬɟ ɨɲɢɛɤɭ ɜ ɪɟɞɚɤɬɨɪɟ ɞɨɛɚɜɥɟɧɢɟɦ ɬɨɱɤɢ ɫ ɡɚɩɹɬɨɣ. ɓɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Save. ɉɪɨɟɤɬ ɛɭɞɟɬ ɩɟɪɟɫɬɪɨɟɧ, ɢ ɢɧɞɢɤɚɬɨɪɵ ɩɪɨɛɥɟɦɵ ɢɫɱɟɡɧɭɬ. 8. ȼ ɩɟɪɫɩɟɤɬɢɜɟ Outline ɜɵɛɟɪɢɬɟ ɦɟɬɨɞ getName(). Ɋɟɞɚɤɬɨɪ ɩɪɨɤɪɭɬɢɬɫɹ ɤ ɷɬɨɦɭ ɦɟɬɨɞɭ. 9. ȼ ɩɟɪɜɨɣ ɫɬɪɨɤɟ ɦɟɬɨɞɚ ɢɡɦɟɧɢɬɟ ɜɨɡɜɪɚɳɚɟɦɭɸ ɩɟɪɟɦɟɧɧɭɸ fName ɧɚ fTestName. ɉɨɤɚ ɛɭɞɟɬɟ ɩɟɱɚɬɚɬɶ, ɧɚ fTestName ɩɨɹɜɢɬɫɹ ɩɨɞɱɟɪɤɢɜɚɧɢɟ, ɢɧɞɢɰɢɪɭɸɳɟɟ ɨɲɢɛɤɭ. ɉɨɦɟɳɟɧɢɟ ɤɭɪɫɨɪɚ ɧɚɞ ɩɨɞɱɟɪɤɧɭɬɨɣ ɨɲɢɛɤɨɣ ɩɪɢɜɟɞɟɬ ɤ ɨɬɨɛɪɚɠɟɧɢɸ ɨɩɢɫɚɧɢɹ ɨɲɢɛɤɢ. 10.ȼ ɨɬɦɟɱɟɧɧɨɣ ɨɛɥɚɫɬɢ ɩɨɹɜɢɬɫɹ ɫɜɟɬɥɨɟ ɩɹɬɧɵɲɤɨ. ɗɬɨ ɩɹɬɧɵɲɤɨ ɫɢɝɧɚɥɢɡɢɪɭɟɬ, ɱɬɨ ɞɥɹ ɷɬɨɣ ɨɲɢɛɤɢ ɢɦɟɸɬɫɹ ɩɪɟɞɥɨɠɟɧɢɹ ɩɨ ɟɟ ɢɫɩɪɚɜɥɟɧɢɸ.
19
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
11.ɍɫɬɚɧɨɜɢɬɟ ɤɭɪɫɨɪ ɜ ɩɪɟɞɟɥɚɯ ɨɬɦɟɱɟɧɧɨɣ ɝɪɚɧɢɰɵ ɢ ɜɵɛɟɪɢɬɟ Quick Fix ɢɡ ɦɟɧɸ Edit. Ɇɨɠɧɨ ɬɚɤɠɟ ɧɚɠɚɬɶ Ctrl+1 ɢɥɢ ɳɟɥɤɧɭɬɶ ɥɟɜɨɣ ɤɥɚɜɢɲɟɣ ɦɵɲɤɢ ɧɚ ɫɜɟɬɥɨɦ ɩɹɬɧɵɲɤɟ. ɉɨɹɜɢɬɫɹ ɞɢɚɥɨɝ ɜɵɛɨɪɚ ɫ ɜɨɡɦɨɠɧɵɦɢ ɢɫɩɪɚɜɥɟɧɢɹɦɢ.
12.ȼɵɛɟɪɢɬɟ Change to 'fName' , ɱɬɨɛɵ ɢɫɩɪɚɜɢɬɶ ɨɲɢɛɤɭ. ɉɨɞɱɟɪɤɢɜɚɧɢɟ ɨɲɢɛɤɢ ɩɪɨɩɚɞɟɬ, ɤɨɝɞɚ ɛɭɞɟɬ ɩɪɢɦɟɧɟɧɨ ɢɫɩɪɚɜɥɟɧɢɟ. 13.Ɂɚɤɪɨɣɬɟ ɮɚɣɥ ɛɟɡ ɫɨɯɪɚɧɟɧɢɹ. 14.Ʉɨɧɮɢɝɭɪɢɪɨɜɚɬɶ ɢɧɞɢɤɚɰɢɸ ɨɲɢɛɨɤ ɦɨɠɧɨ ɧɚ ɫɬɪɚɧɢɰɟ Window > Preferences > General > Editors > Text Editors > Annotations. 3.5. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɲɚɛɥɨɧɨɜ ɢɫɯɨɞɧɨɝɨ ɤɨɞɚ Ȼɭɞɟɦ ɢɫɩɨɥɶɡɨɜɚɬɶ ɤɨɧɬɟɧɬɧɭɸ ɩɨɦɨɳɶ, ɱɬɨɛɵ ɡɚɩɨɥɧɢɬɶ ɲɚɛɥɨɧ (template) ɞɥɹ ɨɛɳɟɣ ɫɬɪɭɤɬɭɪɵ ɰɢɤɥɚ. Ɉɬɤɪɨɣɬɟ ɮɚɣɥ junit.samples.VectorTest.java ɜ ɪɟɞɚɤɬɨɪɟ Java, ɟɫɥɢ ɨɧ ɟɳɟ ɬɚɦ ɧɟ ɨɬɤɪɵɬ. 1. ɇɚɱɧɢɬɟ ɞɨɛɚɜɥɟɧɢɟ ɧɨɜɨɝɨ ɦɟɬɨɞɚ ɫ ɬɨɝɨ, ɱɬɨ ɧɚɩɟɱɚɬɚɣɬɟ ɫɥɟɞɭɸɳɟɟ: public void testValues() { Integer[] expected= new Integer[3]; for
2. Ʉɨɝɞɚ ɤɭɪɫɨɪ ɛɭɞɟɬ ɜ ɤɨɧɰɟ ɫɥɨɜɚ for, ɧɚɠɦɢɬɟ Ctrl+Space, ɱɬɨɛɵ ɡɚɩɭɫɬɢɬɶ ɤɨɧɬɟɧɬɧɭɸ ɩɨɦɨɳɶ. ȼ ɪɟɡɭɥɶɬɚɬɟ ɭɜɢɞɢɬɟ ɫɩɢɫɨɤ ɨɛɳɢɯ ɲɚɛɥɨɧɨɜ ɞɥɹ ɰɢɤɥɨɜ for. Ʉɨɝɞɚ ɩɨɦɟɫɬɢɬɟ ɤɭɪɫɨɪ ɧɚɞ ɲɚɛɥɨɧɨɦ, ɬɨ ɭɜɢɞɢɬɟ ɤɨɞ ɲɚɛɥɨɧɚ ɜ ɟɝɨ ɫɨɨɛɳɟɧɢɢ ɩɨɞɫɤɚɡɤɢ. Ɂɚɦɟɬɶɬɟ, ɱɬɨ ɢɦɹ ɥɨɤɚɥɶɧɨɝɨ ɦɚɫɫɢɜɚ ɭɝɚɞɵɜɚɟɬɫɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ.
20
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
3. ȼɵɛɟɪɢɬɟ ɷɥɟɦɟɧɬ for - iterate over array ɢ ɧɚɠɦɢɬɟ Enter, ɱɬɨɛɵ ɩɨɞɬɜɟɪɞɢɬɶ ɲɚɛɥɨɧ. ɒɚɛɥɨɧ ɛɭɞɟɬ ɜɫɬɚɜɥɟɧ ɜ ɜɚɲ ɢɫɯɨɞɧɵɣ ɤɨɞ.
4. Ɂɚɬɟɦ ɢɡɦɟɧɢɬɟ ɢɦɹ ɢɧɞɟɤɫɧɨɣ ɩɟɪɟɦɟɧɧɨɣ ɫ i ɧɚ e. ɑɬɨɛɵ ɫɞɟɥɚɬɶ ɷɬɨ, ɩɪɨɫɬɨ ɧɚɠɦɢɬɟ ɤɥɚɜɢɲɭ e, ɩɨɫɤɨɥɶɤɭ ɢɧɞɟɤɫɧɚɹ ɩɟɪɟɦɟɧɧɚɹ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɜɵɛɪɚɧɚ. Ɉɛɪɚɬɢɬɟ ɜɧɢɦɚɧɢɟ ɧɚ ɬɨ, ɱɬɨ ɢɧɞɟɤɫɧɚɹ ɩɟɪɟɦɟɧɧɚɹ ɢɡɦɟɧɢɥɚɫɶ ɜɨ ɜɫɟɯ ɦɟɫɬɚɯ. ɉɪɢ ɜɫɬɚɜɤɟ ɲɚɛɥɨɧɚ ɜɫɟ ɩɟɪɟɦɟɧɧɵɟ ɲɚɛɥɨɧɚ ɫ ɨɞɢɧɚɤɨɜɵɦɢ ɢɦɟɧɚɦɢ ɫɜɹɡɵɜɚɸɬɫɹ ɞɪɭɝ ɫ ɞɪɭɝɨɦ. Ɍɚɤ ɱɬɨ ɢɡɦɟɧɟɧɢɟ ɨɞɧɨɣ ɢɡɦɟɧɹɟɬ ɬɚɤɠɟ ɢ ɜɫɟ ɞɪɭɝɢɟ ɡɧɚɱɟɧɢɹ.
5. ɇɚɠɚɬɢɟ ɤɥɚɜɢɲɢ Tab ɩɟɪɟɦɟɳɚɟɬ ɤɭɪɫɨɪ ɧɚ ɩɟɪɟɦɟɧɧɭɸ ɜ ɲɚɛɥɨɧɟ ɤɨɞɚ. ɗɬɨ ɦɚɫɫɢɜ expected.
ɫɥɟɞɭɸɳɭɸ
ɉɨɫɤɨɥɶɤɭ ɦɵ ɧɟ ɯɨɬɢɦ ɦɟɧɹɬɶ ɢɦɹ ɬɚɤ ɤɚɤ ɨɧɨ ɩɪɚɜɢɥɶɧɨ ɭɝɚɞɚɧɨ ɲɚɛɥɨɧɨɦ, ɦɵ ɫɧɨɜɚ ɧɚɠɢɦɚɟɦ Tab ɢ ɩɨɤɢɞɚɟɦ ɲɚɛɥɨɧ, ɩɨɫɤɨɥɶɤɭ ɜ ɧɟɦ ɛɨɥɶɲɟ ɧɟɬ ɩɟɪɟɦɟɧɧɵɯ ɞɥɹ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ. 6. Ɂɚɜɟɪɲɢɬɟ ɰɢɤɥ for ɫɥɟɞɭɸɳɢɦ ɨɛɪɚɡɨɦ: for (int e=0; e < expected.length; e++) { expected[e]= new Integer(e + 1); } Integer[] actual= to 7. ȼ ɤɨɧɰɟ ɫɥɨɜɚ to, ɧɚɠɦɢɬɟ Ctrl+Space ɱɬɨɛɵ ɡɚɩɭɫɬɢɬɶ ɤɨɧɬɟɧɬɧɭɸ ɩɨɦɨɳɶ. ȼɵɛɟɪɢɬɟ toarray - convert collection to array ɢ ɧɚɠɦɢɬɟ Enter,
ɱɬɨɛɵ ɩɨɞɬɜɟɪɞɢɬɶ ɜɵɛɨɪ (ɢɥɢ ɞɜɚɠɞɵ ɳɟɥɤɧɢɬɟ ɧɚ ɜɵɛɨɪɟ). 21
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɒɚɛɥɨɧ ɜɫɬɚɜɥɹɟɬɫɹ ɜ ɪɟɞɚɤɬɨɪ, ɜɵɞɟɥɹɟɬɫɹ ɢ ɜɵɛɢɪɚɟɬɫɹ.
8. ɂɡɦɟɧɢɬɟ ɜɵɛɪɚɧɧɨɟ, ɜɜɟɞɹ Integer. Ɍɢɩ ɤɨɧɫɬɪɭɤɬɨɪɚ ɦɚɫɫɢɜɚ ɢɡɦɟɧɹɟɬɫɹ ɩɪɢ ɢɡɦɟɧɟɧɢɢ ɜɵɛɪɚɧɧɨɝɨ. 9. ɇɚɠɦɢɬɟ Tab, ɱɬɨɛɵ ɩɟɪɟɦɟɫɬɢɬɶ ɜɵɛɨɪ ɧɚ collection ɢ ɢɡɦɟɧɢɬɟ ɟɝɨ, ɜɜɟɞɹ fFull.
10. ɂ ɜɜɟɞɢɬɟ ɫɥɟɞɭɸɳɢɟ ɫɬɪɨɤɢ ɤɨɞɚ, ɱɬɨɛɵ ɡɚɤɨɧɱɢɬɶ ɦɟɬɨɞ: assertEquals(expected.length, actual.length); for (int i= 0; i < actual.length; i++) assertEquals(expected[i], actual[i]);
}
11. ɋɨɯɪɚɧɢɬɟ ɮɚɣɥ. 3.6. Ɉɪɝɚɧɢɡɚɰɢɹ ɨɩɟɪɚɬɨɪɨɜ ɢɦɩɨɪɬɚ Ⱦɚɥɟɟ ɨɪɝɚɧɢɡɭɟɦ ɜ ɢɫɯɨɞɧɨɦ ɤɨɞɟ ɨɛɴɹɜɥɟɧɢɹ ɢɦɩɨɪɬɚ. Ɉɬɤɪɨɣɬɟ ɮɚɣɥ junit.samples.VectorTest.java ɜ ɪɟɞɚɤɬɨɪɟ Java, ɟɫɥɢ ɨɧ ɟɳɟ ɬɚɦ ɧɟ ɨɬɤɪɵɬ. 1. ɍɞɚɥɢɬɟ ɨɛɴɹɜɥɟɧɢɹ ɢɦɩɨɪɬɚ, ɜɵɛɪɚɜ ɢɯ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline ɢ ɜɵɛɪɚɜ Delete ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ. ɉɨɞɬɜɟɪɞɢɬɟ ɜ ɩɨɹɜɢɜɲɟɦɫɹ ɞɢɚɥɨɝɟ – Yes ɢ ɭɜɢɞɢɬɟ ɦɧɨɠɟɫɬɜɨ ɩɪɟɞɭɩɪɟɠɞɟɧɢɣ ɤɨɦɩɢɥɹɬɨɪɚ ɧɚ ɜɟɪɬɢɤɚɥɶɧɨɣ ɥɢɧɟɣɤɟ, ɩɨɫɤɨɥɶɤɭ ɢɫɩɨɥɶɡɭɟɦɵɟ ɜ ɤɨɞɟ ɬɢɩɵ ɛɨɥɶɲɟ ɧɟ ɢɦɩɨɪɬɢɪɭɸɬɫɹ.
22
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
2. ɂɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜ ɪɟɞɚɤɬɨɪɟ ɜɵɛɟɪɢɬɟ Source > Organize Imports. ɇɟɨɛɯɨɞɢɦɵɟ ɨɩɟɪɚɬɨɪɵ ɢɦɩɨɪɬɚ ɞɨɛɚɜɥɹɸɬɫɹ ɜ ɧɚɱɚɥɨ ɜɚɲɟɝɨ ɤɨɞɚ ɩɨɞ ɨɛɴɹɜɥɟɧɢɟɦ ɩɚɤɟɬɚ.
Ɇɨɠɧɨ ɬɚɤɠɟ ɜɵɛɪɚɬɶ Source > Organize Imports ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɨɛɴɹɜɥɟɧɢɣ ɢɦɩɨɪɬɚ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline. Ɂɚɞɚɬɶ ɩɨɪɹɞɨɤ ɨɛɴɹɜɥɟɧɢɣ ɢɦɩɨɪɬɚ ɦɨɠɧɨ ɜ ɧɚɫɬɪɨɣɤɟ Window > Preferences > Java > Code Style > Organize Imports. 3. ɋɨɯɪɚɧɢɬɟ ɮɚɣɥ. 3.7. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɥɨɤɚɥɶɧɨɣ ɢɫɬɨɪɢɢ Ⱦɚɥɟɟ ɛɭɞɟɦ ɢɫɩɨɥɶɡɨɜɚɬɶ ɫɜɨɣɫɬɜɚ ɥɨɤɚɥɶɧɨɣ ɢɫɬɨɪɢɢ, ɱɬɨɛɵ ɩɟɪɟɤɥɸɱɢɬɶɫɹ ɧɚ ɩɪɟɞɵɞɭɳɭɸ ɫɨɯɪɚɧɟɧɧɭɸ ɜɟɪɫɢɸ ɤɨɧɤɪɟɬɧɨɝɨ ɷɥɟɦɟɧɬɚ Java. 1. Ɉɬɤɪɨɣɬɟ ɮɚɣɥ junit.samples.VectorTest.java ɜ ɪɟɞɚɤɬɨɪɟ Java ɢ ɜɵɛɟɪɢɬɟ ɦɟɬɨɞ testCapacity() ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline. 2. ɂɡɦɟɧɢɬɟ ɫɨɞɟɪɠɢɦɨɟ ɦɟɬɨɞɚ ɬɚɤ, ɱɬɨɛɵ ɨɩɟɪɚɬɨɪ for ɱɢɬɚɥɫɹ ɤɚɤ: for (int i= 0; i < 99; i++)
ɋɨɯɪɚɧɢɬɟ ɮɚɣɥ, ɧɚɠɚɜ Ctrl+S. 3. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline ɜɵɛɟɪɢɬɟ ɦɟɬɨɞ testCapacity(), ɢ ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜɵɛɟɪɢɬɟ Replace With > Element from Local History. 4. ȼ ɞɢɚɥɨɝɟ Replace Java Element from Local History ɫɩɢɫɨɤ Local History ɩɨɤɚɡɵɜɚɟɬ ɪɚɡɥɢɱɧɵɟ ɫɨɯɪɚɧɟɧɧɵɟ ɫɨɫɬɨɹɧɢɹ ɦɟɬɨɞɚ. ɉɚɧɟɥɶ Java Source Compare ɩɨɤɚɡɵɜɚɟɬ ɩɨɞɪɨɛɧɨɫɬɢ ɜ ɪɚɡɥɢɱɢɹɯ ɦɟɠɞɭ ɪɟɫɭɪɫɨɦ, ɜɵɛɪɚɧɧɨɦ ɢɡ ɢɫɬɨɪɢɢ, ɢ ɪɟɫɭɪɫɨɦ, ɫɭɳɟɫɬɜɭɸɳɢɦ ɧɚ ɪɚɛɨɱɟɦ ɦɟɫɬɟ. 23
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
5. ȼ ɩɚɧɟɥɢ Local History ɜɵɛɟɪɢɬɟ ɦɟɬɨɞ, ɤɨɬɨɪɵɣ ɢɡɦɟɧɢɥɢ, ɡɚɬɟɦ ɳɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Replace. ȼ ɪɟɞɚɤɬɨɪɟ Java ɦɟɬɨɞ ɡɚɦɟɧɹɟɬɫɹ ɧɚ ɜɟɪɫɢɸ, ɜɵɛɪɚɧɧɭɸ ɢɡ ɢɫɬɨɪɢɢ. 6. ɋɨɯɪɚɧɢɬɟ ɮɚɣɥ. 7. ɉɨɦɢɦɨ ɡɚɦɟɧɵ ɜɟɪɫɢɢ ɦɟɬɨɞɚ ɧɚ ɩɪɟɞɵɞɭɳɭɸ ɦɨɠɧɨ ɬɚɤɠɟ ɜɨɫɫɬɚɧɚɜɥɢɜɚɬɶ ɷɥɟɦɟɧɬɵ Java, ɤɨɬɨɪɵɟ ɛɵɥɢ ɭɞɚɥɟɧɵ. Ɉɩɹɬɶ ɜɵɛɟɪɢɬɟ ɦɟɬɨɞ testCapacity() ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline ɢ ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜɵɛɟɪɢɬɟ Delete. ɉɨɞɬɜɟɪɞɢɬɟ ɜ ɩɨɹɜɢɜɲɟɦɫɹ ɞɢɚɥɨɝɟ Yes ɢ ɫɨɯɪɚɧɢɬɟ ɮɚɣɥ. 8. Ɍɟɩɟɪɶ ɜɵɛɟɪɢɬɟ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline ɬɢɩ VectorTest ɢ ɢɡ ɟɝɨ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜɵɛɟɪɢɬɟ Restore from Local History.... ȼɵɛɟɪɢɬɟ ɢ ɩɪɨɜɟɪɶɬɟ ɦɟɬɨɞ testCapacity() ɜ ɩɚɧɟɥɢ Available Java Elements. Ʉɚɤ ɢ ɩɪɟɠɞɟ, ɩɚɧɟɥɶ Local History ɩɨɤɚɡɵɜɚɟɬ ɜɟɪɫɢɢ, ɫɨɯɪɚɧɟɧɧɵɟ ɜ ɥɨɤɚɥɶɧɨɣ ɢɫɬɨɪɢɢ. ɉɚɧɟɥɶ Java Source Compare ɩɨɤɚɡɵɜɚɟɬ ɩɨɞɪɨɛɧɨɫɬɢ ɜ ɪɚɡɥɢɱɢɹɯ ɦɟɠɞɭ ɪɟɫɭɪɫɨɦ, ɜɵɛɪɚɧɧɨɦ ɢɡ ɢɫɬɨɪɢɢ, ɢ ɪɟɫɭɪɫɨɦ, ɫɭɳɟɫɬɜɭɸɳɢɦ ɧɚ ɪɚɛɨɱɟɦ ɦɟɫɬɟ.
24
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
9. ȼ ɩɚɧɟɥɢ Local History ɜɵɛɟɪɢɬɟ ɪɚɧɧɸɸ ɜɟɪɫɢɸ ɢ ɳɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Restore. 10.ɇɚɠɦɢɬɟ Ctrl+S, ɱɬɨɛɵ ɫɨɯɪɚɧɢɬɶ ɮɚɣɥ. 3.8. ȼɵɞɟɥɟɧɢɟ ɧɨɜɨɝɨ ɦɟɬɨɞɚ Ɂɞɟɫɶ ɛɭɞɟɦ ɢɦɩɨɪɬɢɪɨɜɚɬɶ ɤɨɞ ɤɨɧɫɬɪɭɤɬɨɪɚ junit.framework.TestSuite. ɑɬɨɛɵ ɫɞɟɥɚɬɶ ɹɫɧɨɣ ɰɟɥɶ ɤɨɞɚ, ɜɵɞɟɥɢɬɟ ɤɨɞ, ɜ ɤɨɬɨɪɨɦ ɫɨɛɪɚɧɵ ɬɟɫɬɨɜɵɟ ɱɚɫɬɢ, ɢɡ ɛɚɡɨɜɵɯ ɤɥɚɫɫɨɜ ɜ ɨɬɞɟɥɶɧɵɣ ɦɟɬɨɞ ɫ ɢɦɟɧɟɦ collectTestMethods(). 1. ȼ ɮɚɣɥɟ junit.framework.TestSuite.java ɜɵɞɟɥɢɬɟ ɫɥɟɞɭɸɳɢɣ ɭɱɚɫɬɨɤ ɤɨɞɚ ɜ ɤɨɧɫɬɪɭɤɬɨɪɟ TestSuite(Class): Class superClass= theClass; Vector names= new Vector(); while (Test.class.isAssignableFrom(superClass)) { Method[] methods= superClass.getDeclaredMethods(); for (int i= 0; i < methods.length; i++) { addTestMethod(methods[i], names, theClass); } superClass= superClass.getSuperclass(); }
2. ɂɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜɵɛɨɪɚ ɜ ɪɟɞɚɤɬɨɪɟ ɜɵɛɟɪɢɬɟ Refactor > Extract Method.... 3. ȼ ɩɨɥɟ Method Name ɜɜɟɞɢɬɟ collectInheritedTests.
25
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
4. ɑɬɨɛɵ ɩɪɟɞɜɚɪɢɬɟɥɶɧɨ ɩɪɨɫɦɨɬɪɟɬɶ ɢɡɦɟɧɟɧɢɹ ɧɚɠɦɢɬɟ Preview>. ɋɬɪɚɧɢɰɚ ɩɪɟɞɜɚɪɢɬɟɥɶɧɨɝɨ ɩɪɨɫɦɨɬɪɚ ɨɬɨɛɪɚɠɚɟɬ ɢɡɦɟɧɟɧɢɹ, ɤɨɬɨɪɵɟ ɛɭɞɭɬ ɫɞɟɥɚɧɵ. ɇɚɠɦɢɬɟ OK, ɱɬɨɛɵ ɜɵɞɟɥɢɬɶ ɦɟɬɨɞ. 5. ɉɟɪɟɣɞɢɬɟ ɜ ɜɵɞɟɥɟɧɧɵɣ ɦɟɬɨɞ ɜɵɛɨɪɨɦ ɟɝɨ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline.
3.9. ɋɨɡɞɚɧɢɟ ɤɥɚɫɫɚ Java Ⱦɚɥɟɟ ɫɨɡɞɚɞɢɦ ɤɥɚɫɫ Java ɢ ɞɨɛɚɜɢɦ ɦɟɬɨɞɵ, ɢɫɩɨɥɶɡɭɹ ɞɟɣɫɬɜɢɹ ɝɟɧɟɪɚɰɢɢ ɤɨɞɚ. 1. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɜɵɛɟɪɢɬɟ ɩɪɨɟɤɬ JUnit. ɂɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɩɪɨɟɤɬɚ ɜɵɛɟɪɢɬɟ New > Package ɢɥɢ ɳɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ New Java Package ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ. 2. ȼ ɩɨɥɟ Name ɜɜɟɞɢɬɟ ɢɦɹ ɧɨɜɨɝɨ ɩɚɤɟɬɚ test. Ɂɚɬɟɦ ɳɟɥɤɧɢɬɟ ɧɚ Finish. 3. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɜɵɛɟɪɢɬɟ ɧɨɜɵɣ ɩɚɤɟɬ test ɢ ɳɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ New Java Class ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ. 4. ɍɛɟɞɢɬɟɫɶ, ɱɬɨ JUnit ɩɨɹɜɥɹɟɬɫɹ ɜ ɩɨɥɟ Source Folder ɢ ɱɬɨ test ɩɨɹɜɥɹɟɬɫɹ ɜ ɩɨɥɟ Package. ȼ ɩɨɥɟ Name ɜɜɟɞɢɬɟ MyTestCase.
26
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
5. ɓɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Browse ɡɚ ɩɨɥɟɦ Superclass. 6. ȼ ɩɨɥɟ Choose a type ɜ ɞɢɚɥɨɝɟ Superclass Selection ɜɜɟɞɢɬɟ Test, ɱɬɨɛɵ ɨɝɪɚɧɢɱɢɬɶ ɫɩɢɫɨɤ ɞɨɫɬɭɩɧɵɯ ɫɭɩɟɪɤɥɚɫɫɨɜ.
7. ȼɵɛɟɪɢɬɟ ɤɥɚɫɫ TestCase ɢ ɳɟɥɤɧɢɬɟ ɧɚ OK.
27
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
8. ȼɵɛɟɪɢɬɟ ɮɥɚɠɨɤ Constructors from superclass. 9. ɓɟɥɤɧɢɬɟ ɧɚ Finish, ɱɬɨɛɵ ɫɨɡɞɚɬɶ ɧɨɜɵɣ ɤɥɚɫɫ. 10. ȼ ɪɟɞɚɤɬɨɪɟ ɨɬɤɪɵɜɚɟɬɫɹ ɧɨɜɵɣ ɮɚɣɥ. Ɉɧ ɫɨɞɟɪɠɢɬ ɧɨɜɵɣ ɤɥɚɫɫ, ɤɨɧɫɬɪɭɤɬɨɪ ɢ ɤɨɦɦɟɧɬɚɪɢɢ. Ɉɩɰɢɢ ɞɥɹ ɫɨɡɞɚɧɢɹ ɢ ɤɨɧɮɢɝɭɪɢɪɨɜɚɧɢɹ ɝɟɧɟɪɢɪɭɟɦɵɯ ɤɨɦɦɟɧɬɚɪɢɟɜ ɦɨɠɧɨ ɜɵɛɪɚɬɶ ɜ ɧɚɫɬɪɨɣɤɚɯ Java Window > Preferences > Java > Code Style > Code Templates. 11. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline ɜɵɛɟɪɢɬɟ ɧɨɜɵɣ ɤɥɚɫɫ MyTestCase. Ɉɬɤɪɨɣɬɟ ɤɨɧɬɟɤɫɬɧɨɟ ɦɟɧɸ ɢ ɜɵɛɟɪɢɬɟ Source > Override/Implement Methods...
12. ȼ ɞɢɚɥɨɝɟ Override Methods ɜɵɛɟɪɢɬɟ setUp() ɢ tearDown() ɢ ɳɟɥɤɧɢɬɟ ɧɚ OK. ȼ ɤɥɚɫɫ ɞɨɛɚɜɥɹɸɬɫɹ ɞɜɚ ɦɟɬɨɞɚ.
28
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
13. ɂɡɦɟɧɢɬɟ ɬɟɥɨ setUp() ɧɚ container= new Vector(); 14. container ɢ Vector ɩɨɞɱɟɪɤɢɜɚɸɬɫɹ ɜɵɞɟɥɟɧɢɟɦ ɨɲɢɛɤɢ, ɩɨɫɤɨɥɶɤɭ ɨɧɢ ɧɟ ɦɨɝɭɬ ɛɵɬɶ ɪɚɡɪɟɲɟɧɵ. ɋɜɟɬɥɨɟ ɩɹɬɧɵɲɤɨ ɩɨɹɜɥɹɟɬɫɹ ɧɚ ɦɚɪɤɟɪɧɨɣ ɩɥɚɧɤɟ. ɍɫɬɚɧɨɜɢɬɟ ɤɭɪɫɨɪ ɜɧɭɬɪɢ Vector ɢ ɧɚɠɦɢɬɟ Ctrl+1 ɢɥɢ ɢɫɩɨɥɶɡɭɣɬɟ Edit > Quick Fix ɢɡ ɦɟɧɸ. ȼɵɛɟɪɢɬɟ Import 'Vector' (java.util). ɗɬɨ ɞɨɛɚɜɢɬ ɨɬɫɭɬɫɬɜɭɸɳɟɟ ɨɛɴɹɜɥɟɧɢɟ ɢɦɩɨɪɬɚ.
ɍɫɬɚɧɨɜɢɬɟ ɤɭɪɫɨɪ ɜɧɭɬɪɢ container ɢ ɧɚɠɦɢɬɟ Ctrl+1. ȼɵɛɟɪɢɬɟ Create field 'container', ɱɬɨɛɵ ɞɨɛɚɜɢɬɶ ɧɨɜɨɟ ɩɨɥɟ.
15. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline ɜɵɛɟɪɢɬɟ ɤɥɚɫɫ MyTestCase. Ɉɬɤɪɨɣɬɟ ɤɨɧɬɟɤɫɬɧɨɟ ɦɟɧɸ ɢ ɜɵɛɟɪɢɬɟ Source > Generate Getter and Setter...
29
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
16. Ⱦɢɚɥɨɝ Generate Getter and Setter ɩɪɟɞɩɨɥɚɝɚɟɬ, ɱɬɨ ɫɨɡɞɚɸɬɫɹ ɦɟɬɨɞɵ getContainer() ɢ setContainer(). ȼɵɛɟɪɢɬɟ ɨɛɚ ɢ ɳɟɥɤɧɢɬɟ ɧɚ OK. Ⱦɨɛɚɜɥɹɸɬɫɹ ɦɟɬɨɞɵ-ɚɤɰɟɫɫɨɪɵ ɞɥɹ ɩɨɥɹ.
17. ɋɨɯɪɚɧɢɬɟ ɮɚɣɥ. 18. Ɏɨɪɦɚɬɢɪɨɜɚɧɢɟ ɫɝɟɧɟɪɢɪɨɜɚɧɧɨɝɨ ɤɨɞɚ ɦɨɠɟɬ ɤɨɧɮɢɝɭɪɢɪɨɜɚɬɶɫɹ ɜ Window > Preferences > Java > Code Style > Code Formatter. ȿɫɥɢ ɢɫɩɨɥɶɡɭɟɬɟ ɩɪɟɮɢɤɫ ɢɥɢ ɫɭɮɮɢɤɫ ɞɥɹ ɢɦɟɧɢ ɩɨɥɹ, ɧɚɩɪɢɦɟɪ, fContainer, ɬɨ ɦɨɠɟɬɟ ɡɚɞɚɬɶ ɢɯ ɜ Window > Preferences > Java > Code Style > Fields, ɬɚɤ ɱɬɨ ɫɝɟɧɟɪɢɪɨɜɚɧɧɵɟ ɦɟɬɨɞɵ-ɚɤɰɟɫɫɨɪɵ ɛɭɞɭɬ ɭɝɚɞɵɜɚɬɶ ɢɦɟɧɚ ɦɟɬɨɞɨɜ ɛɟɡ ɩɪɟɮɢɤɫɚ ɢɥɢ ɫɭɮɮɢɤɫɚ. 3.10. ɉɟɪɟɢɦɟɧɨɜɚɧɢɟ ɷɥɟɦɟɧɬɨɜ Java ɇɢɠɟ ɩɟɪɟɢɦɟɧɭɟɦ ɷɥɟɦɟɧɬ Java, ɢɫɩɨɥɶɡɭɹ ɪɟɮɚɤɬɨɪɢɧɝ. Ⱦɟɣɫɬɜɢɹ ɪɟɮɚɤɬɨɪɢɧɝɚ ɢɡɦɟɧɹɸɬ ɫɬɪɭɤɬɭɪɭ ɤɨɞɚ ɛɟɡ ɢɡɦɟɧɟɧɢɹ ɫɟɦɚɧɬɢɤɢ ɩɨɜɟɞɟɧɢɹ. 1. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɜɵɛɟɪɢɬɟ junit.framework.TestCase.java. 30
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
2. ɂɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜɵɛɟɪɢɬɟ Refactor > Rename. 3. ȼ ɩɨɥɟ New name ɧɚ ɫɬɪɚɧɢɰɟ Rename Compilation Unit ɜɜɟɞɢɬɟ TestCase2.
4. ɑɬɨɛɵ ɩɪɟɞɜɚɪɢɬɟɥɶɧɨ ɩɪɨɫɦɨɬɪɟɬɶ ɢɡɦɟɧɟɧɢɹ, ɧɚɠɦɢɬɟ Next >. 5. Ɋɚɛɨɱɟɟ ɦɟɫɬɨ ɚɧɚɥɢɡɢɪɭɟɬ ɩɪɟɞɥɨɠɟɧɧɵɟ ɢɡɦɟɧɟɧɢɹ ɢ ɩɪɟɞɨɫɬɚɜɥɹɟɬ ɜɨɡɦɨɠɧɨɫɬɶ ɩɪɟɞɜɚɪɢɬɟɥɶɧɨɝɨ ɩɪɨɫɦɨɬɪɚ ɢɡɦɟɧɟɧɢɣ, ɤɨɬɨɪɵɟ ɛɭɞɭɬ ɢɦɟɬɶ ɦɟɫɬɨ, ɤɨɝɞɚ ɷɬɨɬ ɪɟɫɭɪɫ ɛɭɞɟɬ ɩɟɪɟɢɦɟɧɨɜɚɧ. ɉɨɫɤɨɥɶɤɭ ɩɟɪɟɢɦɟɧɨɜɚɧɢɟ ɤɨɦɩɢɥɢɪɭɟɦɨɝɨ ɦɨɞɭɥɹ ɩɨɜɥɢɹɟɬ ɧɚ ɨɩɟɪɚɬɨɪɵ ɢɦɩɨɪɬɚ ɜ ɞɪɭɝɢɯ ɤɨɦɩɢɥɢɪɭɟɦɵɯ ɦɨɞɭɥɹɯ, ɞɪɭɝɢɟ ɦɨɞɭɥɢ ɬɚɤɠɟ ɛɭɞɭɬ ɢɡɦɟɧɟɧɵ. ɋɩɢɫɨɤ ɢɡɦɟɧɟɧɢɣ ɩɨɤɚɡɵɜɚɟɬɫɹ ɜ ɩɚɧɟɥɢ ɩɪɟɞɜɚɪɢɬɟɥɶɧɨɝɨ ɩɪɨɫɦɨɬɪɚ.
6. ɇɚ ɩɚɧɟɥɢ ɦɨɠɧɨ ɩɪɨɤɪɭɬɢɬɶ ɩɪɟɞɥɚɝɚɟɦɵɟ ɢɡɦɟɧɟɧɢɹ ɢ ɜɵɛɪɚɬɶ ɢɥɢ ɨɬɦɟɧɢɬɶ ɜɵɛɨɪ ɢɡɦɟɧɟɧɢɣ, ɟɫɥɢ ɷɬɨ ɧɟɨɛɯɨɞɢɦɨ. Ɉɛɵɱɧɨ ɩɪɢɧɢɦɚɸɬɫɹ ɜɫɟ ɩɪɟɞɥɨɠɟɧɧɵɟ ɢɡɦɟɧɟɧɢɹ. 7. ɓɟɥɤɧɢɬɟ ɧɚ Finish, ɱɬɨɛɵ ɩɪɢɧɹɬɶ ɩɪɟɞɥɨɠɟɧɧɵɟ ɢɡɦɟɧɟɧɢɹ. 3.11. ɉɟɪɟɦɟɳɟɧɢɟ ɢ ɤɨɩɢɪɨɜɚɧɢɟ ɷɥɟɦɟɧɬɨɜ Java Ⱦɚɥɟɟ ɛɭɞɟɦ ɢɫɩɨɥɶɡɨɜɚɬɶ ɪɟɮɚɤɬɨɪɢɧɝ ɞɥɹ ɩɟɪɟɦɟɳɟɧɢɹ ɪɟɫɭɪɫɨɜ ɦɟɠɞɭ ɩɚɤɟɬɚɦɢ Java. Ⱦɟɣɫɬɜɢɹ ɪɟɮɚɤɬɨɪɢɧɝɚ ɢɡɦɟɧɹɸɬ ɫɬɪɭɤɬɭɪɭ ɤɨɞɚ ɛɟɡ ɢɡɦɟɧɟɧɢɹ ɫɟɦɚɧɬɢɤɢ ɩɨɜɟɞɟɧɢɹ. 1. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɜɵɛɟɪɢɬɟ ɮɚɣɥ MyTestCase.java ɢɡ ɩɚɤɟɬɚ test ɢ ɨɬɛɭɤɫɢɪɭɣɬɟ ɟɝɨ ɜ ɩɚɤɟɬ junit.samples. Ȼɭɤɫɢɪɨɜɤɚ ɮɚɣɥɚ ɚɧɚɥɨɝɢɱɧɚ ɜɵɛɨɪɭ ɮɚɣɥɚ ɢ ɜɵɛɨɪɭ ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ Refactor > Move. 31
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
2. Ⱦɚɥɟɟ ɩɨɥɭɱɢɬɟ ɩɪɢɝɥɚɲɟɧɢɟ ɜɵɛɪɚɬɶ, ɧɭɠɧɨ ɢɥɢ ɧɟɬ ɢɡɦɟɧɹɬɶ ɫɫɵɥɤɢ ɧɚ ɮɚɣɥ, ɤɨɬɨɪɵɣ ɩɟɪɟɦɟɳɚɟɬɟ. Ɉɛɵɱɧɨ ɷɬɨ ɧɟɨɛɯɨɞɢɦɨ ɫɞɟɥɚɬɶ, ɱɬɨɛɵ ɢɡɛɟɠɚɬɶ ɨɲɢɛɨɤ ɤɨɦɩɢɥɹɰɢɢ. ɇɚɠɦɢɬɟ ɧɚ ɤɧɨɩɤɭ Preview, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɫɩɢɫɨɤ ɢɡɦɟɧɟɧɢɣ, ɤɨɬɨɪɵɟ ɛɭɞɭɬ ɫɞɟɥɚɧɵ ɜ ɪɟɡɭɥɶɬɚɬɟ ɩɟɪɟɦɟɳɟɧɢɹ. 3. ɇɚɠɦɢɬɟ ɧɚ Ok. Ɏɚɣɥ ɩɟɪɟɦɟɳɚɟɬɫɹ, ɢ ɟɝɨ ɨɛɴɹɜɥɟɧɢɟ ɩɚɤɟɬɚ ɢɡɦɟɧɹɟɬɫɹ, ɨɬɪɚɠɚɹ ɟɝɨ ɧɨɜɨɟ ɦɟɫɬɨɩɨɥɨɠɟɧɢɟ.
Ʉɨɧɬɟɤɫɬɧɨɟ ɦɟɧɸ ɹɜɥɹɟɬɫɹ ɚɥɶɬɟɪɧɚɬɢɜɨɣ ɛɭɤɫɢɪɨɜɤɢ. ɉɪɢ ɢɫɩɨɥɶɡɨɜɚɧɢɢ ɦɟɧɸ ɧɟɨɛɯɨɞɢɦɨ ɡɚɞɚɬɶ ɰɟɥɟɜɨɣ ɩɚɤɟɬ ɜ ɞɢɚɥɨɝɟ Move, ɤɪɨɦɟ ɜɵɛɨɪɚ ɢɡɦɟɧɟɧɢɹ ɫɫɵɥɨɤ, ɤɨɬɨɪɵɣ ɭɠɟ ɛɵɥ ɩɨɤɚɡɚɧ. 1. ȼɵɛɟɪɢɬɟ ɮɚɣɥ MyTestCase.java ɢ ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜɵɛɟɪɢɬɟ Refactor > Move. 2. ȼ ɞɢɚɥɨɝɟ Move ɪɚɫɤɪɨɣɬɟ ɢɟɪɚɪɯɢɸ, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɜɨɡɦɨɠɧɵɟ ɧɨɜɵɟ ɦɟɫɬɨɩɨɥɨɠɟɧɢɹ ɪɟɫɭɪɫɚ. ȼɵɛɟɪɢɬɟ ɩɚɤɟɬ junit.samples ɢ ɳɟɥɤɧɢɬɟ ɧɚ OK. Ʉɥɚɫɫ ɩɟɪɟɦɟɳɚɟɬɫɹ, ɢ ɟɝɨ ɨɛɴɹɜɥɟɧɢɟ ɩɚɤɟɬɚ ɢɡɦɟɧɹɟɬɫɹ ɧɚ ɧɨɜɨɟ ɦɟɫɬɨɩɨɥɨɠɟɧɢɟ.
3.12. ɇɚɜɢɝɚɰɢɹ ɩɨ ɨɛɴɹɜɥɟɧɢɹɦ ɷɥɟɦɟɧɬɨɜ Java 1. Ɉɬɤɪɨɣɬɟ ɮɚɣɥ MoneyTest.java ɢɡ ɩɚɤɟɬɚ junit.samples.money ɜ ɪɟɞɚɤɬɨɪɟ Java. 2. ȼ ɩɟɪɜɨɣ ɫɬɪɨɤɟ ɨɛɴɹɜɥɟɧɢɹ ɤɥɚɫɫɚ MoneyTest ɜɵɛɟɪɢɬɟ ɫɭɩɟɪɤɥɚɫɫ TestCase ɢ ɢɡ ɫɬɪɨɤɢ ɦɟɧɸ ɜɵɛɟɪɢɬɟ Navigate > Open Declaration ɢɥɢ ɧɚɠɦɢɬɟ ɧɚ F3. 32
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
Ʉɥɚɫɫ TestCase ɨɬɤɪɵɜɚɟɬɫɹ ɜ ɨɛɥɚɫɬɢ ɪɟɞɚɤɬɨɪɚ ɢ ɬɚɤɠɟ ɩɪɟɞɫɬɚɜɥɹɟɬɫɹ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline.
ɗɬɚ ɤɨɦɚɧɞɚ ɬɚɤɠɟ ɪɚɛɨɬɚɟɬ ɞɥɹ ɦɟɬɨɞɨɜ ɢ ɩɨɥɟɣ. 3. ɉɪɢ ɨɬɤɪɵɬɨɦ ɜ ɪɟɞɚɤɬɨɪɟ TestCase.java ɢ ɜɵɛɪɚɧɧɨɦ ɨɛɴɹɜɥɟɧɢɢ ɤɥɚɫɫɚ ɢɡ ɫɬɪɨɤɢ ɦɟɧɸ ɜɵɛɟɪɢɬɟ Navigate > Open Type Hierarchy ɢɥɢ ɧɚɠɦɢɬɟ F4.
4. Ɉɬɤɪɵɜɚɟɬɫɹ ɩɪɟɞɫɬɚɜɥɟɧɢɟ Hierarchy ɫ ɨɬɨɛɪɚɠɟɧɢɟɦ ɤɥɚɫɫɚ TestCase.
33
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
Ɇɨɠɧɨ ɬɚɤɠɟ ɨɬɤɪɵɜɚɬɶ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Hierarchy.
ɪɟɞɚɤɬɨɪɵ
ɬɢɩɨɜ
ɢ
ɦɟɬɨɞɨɜ
ɜ
3.13. ɉɪɨɫɦɨɬɪ ɢɟɪɚɪɯɢɢ ɬɢɩɨɜ Ⱦɚɥɟɟ ɢɡɭɱɢɦ ɢɫɩɨɥɶɡɨɜɚɧɢɟ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Hierarchy ɩɪɢ ɩɪɨɫɦɨɬɪɟ ɤɥɚɫɫɨɜ ɢ ɢɯ ɱɥɟɧɨɜ ɧɟɫɤɨɥɶɤɢɦɢ ɪɚɡɧɵɦɢ ɫɩɨɫɨɛɚɦɢ. 1. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɧɚɣɞɢɬɟ junit.framework.TestCase.java. ɂɡ ɟɝɨ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜɵɛɟɪɢɬɟ Open Type Hierarchy. Ɇɨɠɧɨ ɬɚɤɠɟ ɨɬɤɪɵɬɶ ɩɪɟɞɫɬɚɜɥɟɧɢɟ ɢɟɪɚɪɯɢɢ ɬɢɩɨɜ ɢɡ ɫɬɪɨɤɢ ɦɟɧɸ, ɜɵɛɪɚɜ Navigate > Open Type Hierarchy ɢɥɢ ɧɚɠɚɬɶ F4 ɩɨɫɥɟ ɜɵɛɨɪɚ TestCase.java.
2. Ʉɧɨɩɤɢ ɧɚ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɭɩɪɚɜɥɹɸɬ ɬɟɦ, ɤɚɤɚɹ ɱɚɫɬɶ ɢɟɪɚɪɯɢɢ ɩɨɤɚɡɵɜɚɟɬɫɹ. ɓɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Show the Type Hierarchy, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɢɟɪɚɪɯɢɸ ɤɥɚɫɫɨɜ, ɜɤɥɸɱɚɹ ɛɚɡɨɜɵɟ ɤɥɚɫɫɵ ɢ ɩɨɞɤɥɚɫɫɵ. Ɇɚɥɟɧɶɤɚɹ ɫɬɪɟɥɤɚ ɫ ɥɟɜɨɣ ɫɬɨɪɨɧɵ ɨɬ ɢɤɨɧɤɢ ɬɢɩɚ TestCase ɩɨɤɚɡɵɜɚɟɬ, ɱɬɨ ɢɟɪɚɪɯɢɹ ɛɵɥɚ ɨɬɤɪɵɬɚ ɞɥɹ ɷɬɨɝɨ ɬɢɩɚ.
34
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
3. ɓɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Show the Supertype Hierarchy, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɢɟɪɚɪɯɢɸ ɧɚ ɪɨɞɢɬɟɥɶɫɤɢɯ ɷɥɟɦɟɧɬɚɯ ɬɢɩɚ, ɜɤɥɸɱɚɹ ɪɟɚɥɢɡɨɜɚɧɧɵɟ ɢɧɬɟɪɮɟɣɫɵ. ɗɬɨ ɩɪɟɞɫɬɚɜɥɟɧɢɟ ɩɨɤɚɡɵɜɚɟɬ ɪɟɡɭɥɶɬɚɬ ɞɜɢɠɟɧɢɹ ɜɜɟɪɯ ɩɨ ɢɟɪɚɪɯɢɢ ɬɢɩɨɜ.
ȼ ɷɬɨɦ ɩɪɟɞɫɬɚɜɥɟɧɢɢ «ɪɟɜɟɪɫɢɜɧɨɣ ɢɟɪɚɪɯɢɢ» ɦɨɠɧɨ ɭɜɢɞɟɬɶ, ɱɬɨ TestCase ɪɟɚɥɢɡɭɟɬ ɢɧɬɟɪɮɟɣɫ Test. 4. ɓɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Show the Subtype Hierarchy ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɩɪɟɞɫɬɚɜɥɟɧɢɹ.
5. ɓɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Lock View and Show Members in Hierarchy ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɩɚɧɟɥɢ ɱɥɟɧɨɜ ɤɥɚɫɫɚ ɢ ɜɵɛɟɪɢɬɟ ɦɟɬɨɞ runTest () ɜ ɩɚɧɟɥɢ ɱɥɟɧɨɜ ɤɥɚɫɫɚ. ɉɪɟɞɫɬɚɜɥɟɧɢɟ ɬɟɩɟɪɶ ɩɨɤɚɡɵɜɚɟɬ ɜɫɟ ɬɢɩɵ, ɪɟɚɥɢɡɭɸɳɢɟ runTest ().
35
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
6. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Hierarchy ɳɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Show the Supertype Hierarchy. Ɂɚɬɟɦ ɧɚ ɩɚɧɟɥɢ ɱɥɟɧɨɜ ɤɥɚɫɫɚ ɜɵɛɟɪɢɬɟ countTestCases (), ɜ ɤɨɬɨɪɵɯ ɷɬɨɬ ɦɟɬɨɞ ɨɛɴɹɜɥɟɧ.
7. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Hierarchy ɜɵɛɟɪɢɬɟ ɷɥɟɦɟɧɬ Test ɢ ɜɵɛɟɪɢɬɟ Focus On 'Test' ɢɡ ɟɝɨ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ. Test ɩɪɟɞɫɬɚɜɥɹɟɬɫɹ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Hierarchy. 8. Ⱥɤɬɢɜɢɡɢɪɭɣɬɟ ɩɪɟɞɫɬɚɜɥɟɧɢɟ Package Explorer ɢ ɜɵɛɟɪɢɬɟ ɩɚɤɟɬ junit.framework. ɂɫɩɨɥɶɡɭɣɬɟ Open Type Hierarchy ɢɡ ɟɝɨ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ. Ɉɬɤɪɵɜɚɟɬɫɹ ɢɟɪɚɪɯɢɹ, ɫɨɞɟɪɠɚɳɚɹ ɜɫɟ ɤɥɚɫɫɵ ɩɚɤɟɬɚ. Ⱦɥɹ ɡɚɜɟɪɲɟɧɧɨɫɬɢ ɞɟɪɟɜɚ ɢɟɪɚɪɯɢɹ ɬɚɤɠɟ ɩɨɤɚɡɵɜɚɟɬ ɧɟɤɨɬɨɪɵɟ ɤɥɚɫɫɵ ɢɡ ɞɪɭɝɢɯ ɩɚɤɟɬɨɜ. ɗɬɢ ɬɢɩɵ ɩɨɤɚɡɵɜɚɸɬɫɹ ɢɤɨɧɤɚɦɢ ɬɢɩɨɜ ɫ ɛɟɥɨɣ ɡɚɤɪɚɫɤɨɣ. 36
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
9. ɂɫɩɨɥɶɡɭɣɬɟ Previous Type Hierarchies, ɱɬɨɛɵ ɜɟɪɧɭɬɶɫɹ ɤ ɪɚɧɟɟ ɨɬɤɪɵɬɨɦɭ ɷɥɟɦɟɧɬɭ. ɓɟɥɤɧɢɬɟ ɧɚ ɫɬɪɟɥɤɟ ɡɚ ɤɧɨɩɤɨɣ, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɫɩɢɫɨɤ ɷɥɟɦɟɧɬɨɜ, ɢɥɢ ɠɟ ɳɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ ɞɥɹ ɪɟɞɚɤɬɢɪɨɜɚɧɢɹ ɫɩɢɫɤɚ ɢɫɬɨɪɢɢ.
10. ɂɡ ɫɬɪɨɤɢ ɦɟɧɸ ɜɵɛɟɪɢɬɟ Window > Preferences. ɉɟɪɟɣɞɢɬɟ ɤ Java ɢ ɜɵɛɟɪɢɬɟ Open a new Type Hierarchy Perspective. Ɂɚɬɟɦ ɳɟɥɤɧɢɬɟ ɧɚ OK. 11. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Hierarchy ɜɵɛɟɪɢɬɟ ɫɧɨɜɚ ɷɥɟɦɟɧɬ Test ɢ ɚɤɬɢɜɢɡɢɪɭɣɬɟ Open Type Hierarchy ɢɡ ɫɬɪɨɤɢ ɦɟɧɸ Navigate. Ɋɟɫɭɪɫ, ɫɨɞɟɪɠɚɳɢɣ ɜɵɛɪɚɧɧɵɣ ɬɢɩ, ɩɨɤɚɡɵɜɚɟɬɫɹ ɜ ɧɨɜɨɦ ɩɪɟɞɫɬɚɜɥɟɧɢɢ (ɩɪɟɞɫɬɚɜɥɟɧɢɢ Hierarchy), ɢ ɟɝɨ ɢɫɯɨɞɧɵɣ ɤɨɞ ɩɨɤɚɡɵɜɚɟɬɫɹ ɜ ɪɟɞɚɤɬɨɪɟ Java. ɍɫɬɚɧɨɜɤɨɣ ɨɩɰɢɣ ɧɚɫɬɪɨɣɤɢ ɞɥɹ ɩɪɨɫɦɨɬɪɚ ɩɪɟɞɫɬɚɜɥɟɧɢɣ ɢɟɪɚɪɯɢɣ ɬɢɩɨɜ ɦɨɠɧɨ ɩɨɥɭɱɢɬɶ ɛɨɥɟɟ ɨɞɧɨɣ ɢɟɪɚɪɯɢɢ ɬɢɩɨɜ ɧɚ ɪɚɛɨɱɟɦ ɦɟɫɬɟ ɢ ɩɟɪɟɤɥɸɱɚɬɶɫɹ ɦɟɠɞɭ ɧɢɦɢ ɩɪɢ ɧɟɨɛɯɨɞɢɦɨɫɬɢ. 4. ɉɨɢɫɤ ɜ ɪɚɛɨɱɟɦ ɦɟɫɬɟ ȼ ɞɢɚɥɨɝɟ Search ɦɨɠɧɨ ɜɵɩɨɥɧɹɬɶ ɩɨɢɫɤ ɮɚɣɥɨɜ, ɬɟɤɫɬɨɜ ɢɥɢ ɷɥɟɦɟɧɬɨɜ Java. ɉɨɢɫɤɢ Java ɨɩɟɪɢɪɭɸɬ ɫɨ ɫɬɪɭɤɬɭɪɚɦɢ ɤɨɞɚ. ɉɨɢɫɤɢ ɮɚɣɥɨɜ ɨɩɟɪɢɪɭɸɬ ɫ ɮɚɣɥɚɦɢ ɩɨ ɢɯ ɢɦɟɧɚɦ ɢ/ɢɥɢ ɬɟɤɫɬɨɜɨɦɭ ɫɨɞɟɪɠɢɦɨɦɭ. ɉɨɢɫɤɢ Java ɛɨɥɟɟ ɛɵɫɬɪɵɟ, ɩɨɫɤɨɥɶɤɭ ɨɧɢ ɩɨɞɞɟɪɠɢɜɚɸɬɫɹ ɢɧɞɟɤɫɚɦɢ ɜ ɫɬɪɭɤɬɭɪɟ ɤɨɞɚ. Ɍɟɤɫɬɨɜɵɟ ɩɨɢɫɤɢ ɩɨɡɜɨɥɹɸɬ ɜɚɦ ɧɚɯɨɞɢɬɶ ɫɨɨɬɜɟɬɫɬɜɢɹ ɜɧɭɬɪɢ ɤɨɦɦɟɧɬɚɪɢɟɜ ɢ ɫɬɪɨɤ. 4.1. ȼɵɩɨɥɧɟɧɢɟ ɩɨɢɫɤɚ Java ɢɡ ɪɚɛɨɱɟɝɨ ɦɟɫɬɚ 1. ȼ ɩɟɪɫɩɟɤɬɢɜɟ Java ɳɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Search ɧɚ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɪɚɛɨɱɟɝɨ ɦɟɫɬɚ ɢɥɢ ɢɫɩɨɥɶɡɭɣɬɟ Search > Java ɢɡ ɫɬɪɨɤɢ ɦɟɧɸ. 2. ȿɫɥɢ ɨɧɚ ɟɳɟ ɧɟ ɜɵɛɪɚɧɚ, ɜɵɛɟɪɢɬɟ ɡɚɤɥɚɞɤɭ Java Search.
37
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
3. ȼ ɩɨɥɟ Search string ɜɜɟɞɢɬɟ runTest. ȼ ɨɛɥɚɫɬɢ Search For ɜɵɛɟɪɢɬɟ Method, ɚ ɜ ɨɛɥɚɫɬɢ Limit To ɜɵɛɟɪɢɬɟ References. ɉɪɨɜɟɪɶɬɟ, ɱɬɨ Scope ɭɫɬɚɧɨɜɥɟɧɨ ɜ Workspace.
Ɂɚɬɟɦ ɳɟɥɤɧɢɬɟ ɧɚ Search. ȼɨ ɜɪɟɦɹ ɩɨɢɫɤɚ ɦɨɠɧɨ ɜ ɥɸɛɨɣ ɦɨɦɟɧɬ ɳɟɥɤɧɭɬɶ ɧɚ Cancel, ɱɬɨɛɵ ɨɫɬɚɧɨɜɢɬɶ ɩɨɢɫɤ. Ȼɭɞɭɬ ɩɨɤɚɡɚɧɵ ɱɚɫɬɢɱɧɵɟ ɪɟɡɭɥɶɬɚɬɵ. 4. ȼ ɩɟɪɫɩɟɤɬɢɜɟ Java ɩɪɟɞɫɬɚɜɥɟɧɢɟ Search ɩɨɤɚɡɵɜɚɟɬ ɪɟɡɭɥɶɬɚɬɵ ɩɨɢɫɤɚ.
ɂɫɩɨɥɶɡɭɣɬɟ ɤɧɨɩɤɢ Show Next Match ɢ Show Previous Match ɞɥɹ ɧɚɜɢɝɚɰɢɢ ɩɨ ɫɨɨɬɜɟɬɫɬɜɢɹɦ. ȿɫɥɢ ɮɚɣɥ, ɜ ɤɨɬɨɪɨɦ ɧɚɣɞɟɧɨ ɫɨɨɬɜɟɬɫɬɜɢɟ, ɫɟɣɱɚɫ ɧɟ ɨɬɤɪɵɬ, ɨɧ ɨɬɤɪɵɜɚɟɬɫɹ ɜ ɪɟɞɚɤɬɨɪɟ. 5. Ʉɨɝɞɚ ɩɟɪɟɞɜɢɝɚɟɬɟɫɶ ɩɨ ɫɨɨɬɜɟɬɫɬɜɢɹɦ, ɢɫɩɨɥɶɡɭɹ ɤɧɨɩɤɢ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Search, ɮɚɣɥ ɨɬɤɪɵɜɚɟɬɫɹ ɜ ɪɟɞɚɤɬɨɪɟ ɧɚ ɩɨɡɢɰɢɢ ɫɨɨɬɜɟɬɫɬɜɢɹ. ɇɚɣɞɟɧɧɵɟ ɫɨɨɬɜɟɬɫɬɜɢɹ ɨɬɦɟɱɚɸɬɫɹ ɦɚɪɤɟɪɨɦ ɧɚ ɜɟɪɬɢɤɚɥɶɧɨɣ ɥɢɧɟɣɤɟ. 4.2. ɉɨɢɫɤ ɢɡ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Java ɉɨɢɫɤɢ Java ɦɨɝɭɬ ɬɚɤɠɟ ɜɵɩɨɥɧɹɬɶɫɹ ɢɡ ɨɩɪɟɞɟɥɟɧɧɵɯ ɩɪɟɞɫɬɚɜɥɟɧɢɣ, ɜɤɥɸɱɚɹ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Outline, Hierarchy ɢ Package Explorer. 1. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɞɜɚɠɞɵ ɳɟɥɤɧɢɬɟ ɧɚ junit.framework.Assert.java, ɱɬɨɛɵ ɨɬɤɪɵɬɶ ɟɝɨ ɜ ɪɟɞɚɤɬɨɪɟ. 2. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline ɜɵɛɟɪɢɬɟ ɦɟɬɨɞ fail(String) , ɚ ɢɡ ɟɝɨ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜɵɛɟɪɢɬɟ References > Workspace.
38
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
4.3. ɉɨɢɫɤ ɢɡ ɪɟɞɚɤɬɨɪɚ ɂɡ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Package Explorer ɨɬɤɪɨɣɬɟ junit.framework.TestCase.java. ȼ ɪɟɞɚɤɬɨɪɟ ɜɵɛɟɪɢɬɟ ɢɦɹ ɤɥɚɫɫɚ TestCase ɢ ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜɵɛɟɪɢɬɟ References > Workspace.
4.4. ɉɪɨɞɨɥɠɟɧɢɟ ɩɨɢɫɤɚ ɢɡ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɩɨɢɫɤɚ ɉɪɟɞɫɬɚɜɥɟɧɢɟ Search ɩɨɤɚɡɵɜɚɟɬ ɪɟɡɭɥɶɬɚɬɵ ɩɨɢɫɤɚ ɞɥɹ TestCase. ȼɵɛɟɪɢɬɟ ɪɟɡɭɥɶɬɚɬ ɩɨɢɫɤɚ ɢ ɨɬɤɪɨɣɬɟ ɤɨɧɬɟɤɫɬɧɨɟ ɦɟɧɸ. Ɇɨɠɧɨ ɩɪɨɞɨɥɠɢɬɶ ɩɨɢɫɤ ɫɫɵɥɨɤ ɢ ɨɛɴɹɜɥɟɧɢɣ ɜɵɛɪɚɧɧɨɝɨ ɷɥɟɦɟɧɬɚ.
39
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
4.5. ȼɵɩɨɥɧɟɧɢɟ ɩɨɢɫɤɚ ɮɚɣɥɨɜ 1. ȼ ɩɟɪɫɩɟɤɬɢɜɟ Java ɳɟɥɤɧɢɬɟ ɧɚ ɤɧɨɩɤɟ Search ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɪɚɛɨɱɟɝɨ ɦɟɫɬɚ ɢɥɢ ɜɵɛɟɪɢɬɟ Search > File ɢɡ ɫɬɪɨɤɢ ɦɟɧɸ. 2. ȿɫɥɢ ɨɧɚ ɟɳɟ ɧɟ ɜɵɛɪɚɧɚ, ɜɵɛɟɪɢɬɟ ɡɚɤɥɚɞɤɭ File Search. 3. ȼ ɩɨɥɟ Containing text ɜɜɟɞɢɬɟ TestCase. ɍɛɟɞɢɬɟɫɶ, ɱɬɨ ɩɨɥɟ File name patterns ɭɫɬɚɧɨɜɥɟɧɨ ɜ *.java. Scope ɞɨɥɠɧɨ ɛɵɬɶ ɭɫɬɚɧɨɜɥɟɧɨ ɜ Workspace. Ɂɚɬɟɦ ɳɟɥɤɧɢɬɟ ɧɚ Search.
4. ɑɬɨɛɵ ɧɚɣɬɢ ɜɫɟ ɮɚɣɥɵ ɞɥɹ ɡɚɞɚɧɧɨɝɨ ɲɚɛɥɨɧɚ ɢɦɟɧɢ, ɨɫɬɚɜɶɬɟ ɩɨɥɟ Containing Text ɩɭɫɬɵɦ. 4.6. ɉɪɨɫɦɨɬɪ ɩɪɟɞɵɞɭɳɢɯ ɪɟɡɭɥɶɬɚɬɨɜ ɩɨɢɫɤɚ ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Search ɳɟɥɤɧɢɬɟ ɧɚ ɫɬɪɟɥɤɟ ɫɥɟɞɭɸɳɟɣ ɡɚ ɤɧɨɩɤɨɣ Show Previous Searches, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɦɟɧɸ, ɫɨɞɟɪɠɚɳɟɟ ɫɩɢɫɨɤ ɛɨɥɶɲɢɧɫɬɜɚ ɩɨɫɥɟɞɧɢɯ ɩɨɢɫɤɨɜ. Ɇɨɠɧɨ ɜɵɛɪɚɬɶ ɷɥɟɦɟɧɬ ɢɡ ɦɟɧɸ, ɱɬɨɛɵ ɭɜɢɞɟɬɶ ɩɪɟɞɵɞɭɳɢɟ ɩɨɢɫɤɢ. ɋɩɢɫɨɤ ɦɨɠɟɬ ɛɵɬɶ ɨɱɢɳɟɧ ɜɵɛɨɪɨɦ Clear History.
40
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
Ʉɧɨɩɤɚ Show Previous Searches ɛɭɞɟɬ ɨɬɨɛɪɚɠɚɬɶ ɞɢɚɥɨɝ ɫɨ ɫɩɢɫɤɨɦ ɜɫɟɯ ɩɪɟɞɵɞɭɳɢɯ ɩɨɢɫɤɨɜ ɜ ɬɟɤɭɳɟɦ ɫɟɚɧɫɟ.
ȼɵɛɨɪ ɩɪɟɞɵɞɭɳɟɝɨ ɩɨɢɫɤɚ ɢɡ ɷɬɨɝɨ ɞɢɚɥɨɝɚ ɩɨɡɜɨɥɢɬ ɜɚɦ ɩɪɨɫɦɨɬɪɟɬɶ ɷɬɢ ɩɨɢɫɤɢ. 5. Ɂɚɩɭɫɤ ɩɪɨɝɪɚɦɦ 1. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɧɚɣɞɢɬɟ junit.textui.TestRunner.java ɢ ɞɜɚɠɞɵ ɳɟɥɤɧɢɬɟ ɧɚ ɧɟɦ, ɱɬɨɛɵ ɨɬɤɪɵɬɶ ɟɝɨ ɜ ɪɟɞɚɤɬɨɪɟ. 2. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Outline ɡɚɦɟɬɶɬɟ, ɱɬɨ ɤɥɚɫɫ TestRunner ɢɦɟɟɬ ɢɤɨɧɤɭ, ɤɨɬɨɪɚɹ ɩɨɤɚɡɵɜɚɟɬ, ɱɬɨ ɜ ɤɥɚɫɫɟ ɨɩɪɟɞɟɥɟɧ ɦɟɬɨɞ main.
3. ɓɟɥɤɧɢɬɟ ɩɪɚɜɨɣ ɤɥɚɜɢɲɟɣ ɧɚ TestRunner.java ɜ Package Explorer ɢ ɜɵɛɟɪɢɬɟ ɢɡ ɜɵɩɚɞɚɸɳɟɝɨ ɦɟɧɸ Run As > Java Application. ɗɬɨ ɩɪɢɜɟɞɟɬ ɤ ɡɚɝɪɭɡɤɟ ɜɵɛɪɚɧɧɨɝɨ ɤɥɚɫɫɚ ɤɚɤ ɥɨɤɚɥɶɧɨɝɨ ɩɪɢɥɨɠɟɧɢɹ Java. ɗɥɟɦɟɧɬ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ Run As ɬɚɤɠɟ ɞɨɫɬɭɩɟɧ ɢ ɜ ɞɪɭɝɢɯ ɦɟɫɬɚɯ, ɬɚɤɢɯ ɤɚɤ ɩɪɟɞɫɬɚɜɥɟɧɢɟ Outline. 4. Ɂɚɦɟɬɶɬɟ, ɱɬɨ ɩɪɨɝɪɚɦɦɚ ɡɚɤɨɧɱɢɥɚ ɜɵɩɨɥɧɟɧɢɟ ɢ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Console ɩɨɹɜɢɥɨɫɶ ɫɥɟɞɭɸɳɟɟ ɫɨɨɛɳɟɧɢɟ, ɝɨɜɨɪɹɳɟɟ, ɱɬɨ ɩɪɨɝɪɚɦɦɟ ɧɭɠɟɧ ɚɪɝɭɦɟɧɬ ɜɵɩɨɥɧɟɧɢɹ. Ɂɚɩɭɫɤ ɩɪɨɝɪɚɦɦ ɤɚɤ Java Application ɢɫɩɨɥɶɡɭɟɬ ɭɫɬɚɧɨɜɤɢ ɩɨ ɭɦɨɥɱɚɧɢɸ ɞɥɹ ɡɚɝɪɭɡɤɢ ɜɵɛɪɚɧɧɨɝɨ ɤɥɚɫɫɚ ɢ ɧɟ ɩɨɡɜɨɥɹɟɬ ɜɚɦ ɡɚɞɚɜɚɬɶ ɤɚɤɢɟ-ɥɢɛɨ ɚɪɝɭɦɟɧɬɵ.
41
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
5. ɑɬɨɛɵ ɡɚɞɚɬɶ ɚɪɝɭɦɟɧɬɵ, ɢɫɩɨɥɶɡɭɣɬɟ ɤɨɧɬɟɤɫɬɧɨɟ ɦɟɧɸ Run As > Run.... ɢɥɢ ɜɵɩɚɞɚɸɳɟɟ ɦɟɧɸ ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɢ ɜɵɛɟɪɢɬɟ
6. ɉɪɢ ɷɬɨɦ ɨɬɤɪɵɜɚɟɬɫɹ ɞɢɚɥɨɝ ɫ ɜɵɛɪɚɧɧɨɣ ɤɨɧɮɢɝɭɪɚɰɢɟɣ ɡɚɝɪɭɡɤɢ TestRunner, ɤɨɬɨɪɚɹ ɩɨɡɜɨɥɹɟɬ ɤɨɧɮɢɝɭɪɢɪɨɜɚɬɶ ɡɚɝɪɭɡɤɭ ɩɪɨɝɪɚɦɦɵ, ɜɤɥɸɱɚɹ ɟɟ ɚɪɝɭɦɟɧɬɵ, classpath ɢ ɞɪɭɝɢɟ ɨɩɰɢɢ. Ʉɨɧɮɢɝɭɪɚɰɢɹ ɡɚɝɪɭɡɤɢ ɛɵɥɚ ɫɨɡɞɚɧɚ ɩɨ ɭɦɨɥɱɚɧɢɸ ɩɪɢ ɜɵɛɨɪɟ Run As > Java Application.
7. ȼɵɛɟɪɢɬɟ ɡɚɤɥɚɞɤɭ Arguments ɢ ɜɜɟɞɢɬɟ junit.samples.VectorTest ɜ Program arguments area.
8. ɓɟɥɤɧɢɬɟ ɧɚ Run. Ɍɟɩɟɪɶ ɩɪɨɝɪɚɦɦɚ ɡɚɩɭɫɤɚɟɬɫɹ ɩɪɚɜɢɥɶɧɨ, ɩɨɤɚɡɵɜɚɹ ɤɨɥɢɱɟɫɬɜɨ ɬɟɫɬɨɜ, ɤɨɬɨɪɵɟ ɜɵɩɨɥɧɢɥɢɫɶ.
9. ɉɟɪɟɤɥɸɱɢɬɟɫɶ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɟ Debug. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Debug ɜɢɞɧɨ, ɱɬɨ ɩɪɨɰɟɫɫ ɞɥɹ ɩɨɫɥɟɞɧɟɣ ɡɚɝɪɭɡɤɢ ɩɪɨɝɪɚɦɦɵ ɛɵɥ 42
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɡɚɪɟɝɢɫɬɪɢɪɨɜɚɧ, ɤɨɝɞɚ ɩɪɨɝɪɚɦɦɚ ɛɵɥɚ ɡɚɩɭɳɟɧɚ. ɉɨ ɭɦɨɥɱɚɧɢɸ ɩɪɟɞɫɬɚɜɥɟɧɢɟ Debug ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɭɞɚɥɹɟɬ ɥɸɛɵɟ ɩɪɟɪɜɚɧɧɵɟ ɡɚɝɪɭɡɤɢ, ɤɨɝɞɚ ɫɨɡɞɚɟɬɫɹ ɧɨɜɚɹ ɡɚɝɪɭɡɤɚ. ɗɬɚ ɨɩɰɢɹ ɦɨɠɟɬ ɤɨɧɮɢɝɭɪɢɪɨɜɚɬɶɫɹ ɧɚ ɫɬɪɚɧɢɰɟ ɧɚɫɬɪɨɟɤ Window > Praferences…> Run/Debug > Launching.
Ɇɨɠɧɨ ɩɟɪɟɡɚɩɭɫɬɢɬɶ ɩɪɟɪɜɚɧɧɵɣ ɩɪɨɰɟɫɫ ɜɵɛɨɪɨɦ Relaunch ɢɡ ɟɝɨ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ. 10. ȼɵɛɟɪɢɬɟ ɜɵɩɚɞɚɸɳɟɟ ɦɟɧɸ ɤɧɨɩɤɢ Run ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɪɚɛɨɱɟɝɨ ɦɟɫɬɚ. ɗɬɨɬ ɫɩɢɫɨɤ ɫɨɞɟɪɠɢɬ ɪɚɧɟɟ ɡɚɩɭɳɟɧɧɵɟ ɩɪɨɝɪɚɦɦɵ. ɗɬɢ ɩɪɨɝɪɚɦɦɵ ɦɨɝɭɬ ɛɵɬɶ ɩɟɪɟɡɚɩɭɳɟɧɵ ɜɵɛɨɪɨɦ ɢɯ ɢɡ ɫɩɢɫɤɚ ɢɫɬɨɪɢɢ.
11. ɂɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Debug (ɢɥɢ ɷɤɜɢɜɚɥɟɧɬɧɨɣ ɤɧɨɩɤɢ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ) ɜɵɛɟɪɢɬɟ Remove All Terminated, ɱɬɨɛɵ ɨɱɢɫɬɢɬɶ ɩɪɟɞɫɬɚɜɥɟɧɢɟ ɩɪɟɪɜɚɧɧɵɯ ɡɚɩɭɳɟɧɧɵɯ ɩɪɨɰɟɫɫɨɜ.
6. Ɉɬɥɚɞɤɚ ɩɪɨɝɪɚɦɦ ɉɪɨɰɟɫɫ ɨɬɥɚɞɤɢ ɩɪɨɝɪɚɦɦ ɨɫɭɳɟɫɬɜɥɹɟɬɫɹ ɜ ɫɥɟɞɭɸɳɟɣ ɩɨɫɥɟɞɨɜɚɬɟɥɶɧɨɫɬɢ: 1. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɜ ɩɟɪɫɩɟɤɬɢɜɟ Java ɞɜɚɠɞɵ ɳɟɥɤɧɢɬɟ ɧɚ junit.samples.VectorTest.java, ɱɬɨɛɵ ɨɬɤɪɵɬɶ ɟɝɨ ɜ ɪɟɞɚɤɬɨɪɟ. 2. ɉɨɦɟɫɬɢɬɟ ɤɭɪɫɨɪ ɧɚ ɜɟɪɬɢɤɚɥɶɧɭɸ ɥɢɧɟɣɤɭ ɜɞɨɥɶ ɥɟɜɨɝɨ ɤɪɚɹ ɨɛɥɚɫɬɢ ɪɟɞɚɤɬɨɪɚ ɧɚ ɫɥɟɞɭɸɳɟɣ ɫɬɪɨɤɭ ɦɟɬɨɞɚ setUp(): fFull.addElement(new Integer(1));
ɢ ɞɜɚɠɞɵ ɳɟɥɤɧɢɬɟ ɧɚ ɥɢɧɟɣɤɟ, ɱɬɨɛɵ ɭɫɬɚɧɨɜɢɬɶ ɬɨɱɤɭ ɨɫɬɚɧɨɜɚ.
43
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɂɤɨɧɤɚ ɬɨɱɤɢ ɨɫɬɚɧɨɜɚ ɩɨɤɚɡɵɜɚɟɬ ɫɬɚɬɭɫ ɬɨɱɤɢ ɨɫɬɚɧɨɜɚ. Ʉɨɝɞɚ ɤɥɚɫɫ ɡɚɝɪɭɠɟɧ ɜ Java VM, ɬɨɱɤɚ ɨɫɬɚɧɨɜɚ ɛɭɞɟɬ ɭɫɬɚɧɨɜɥɟɧɚ, ɢ ɨɬɦɟɬɤɚ ɨɛ ɷɬɨɦ ɛɭɞɟɬ ɨɬɨɛɪɚɠɟɧɚ ɧɚ ɢɤɨɧɤɟ ɬɨɱɤɢ ɨɫɬɚɧɨɜɚ. 3. ȼ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Package Explorer ɜɵɛɟɪɢɬɟ ɩɚɤɟɬ junit.samples ɢ ɜɵɛɟɪɢɬɟ ɦɟɧɸ Run. ȼ ɦɟɧɸ Run ɜɵɛɟɪɢɬɟ Debug As, ɚ ɡɚɬɟɦ Java Application. Ʉɨɝɞɚ ɡɚɩɭɫɬɢɬɫɹ ɩɪɨɝɪɚɦɦɚ ɢɡ ɩɚɤɟɬɚ, ɬɨ ɩɨɥɭɱɢɬɟ ɩɪɢɝɥɚɲɟɧɢɟ ɜɵɛɪɚɬɶ ɬɢɩ ɢɡ ɜɫɟɯ ɤɥɚɫɫɨɜ, ɝɞɟ ɨɩɪɟɞɟɥɟɧ ɦɟɬɨɞ main. 4. ȼɵɛɟɪɢɬɟ ɷɥɟɦɟɧɬ VectorTest - junit.samples - JUnit ɜ ɞɢɚɥɨɝɟ ɢ ɳɟɥɤɧɢɬɟ ɧɚ OK.
5. ɉɪɨɝɪɚɦɦɚ ɛɭɞɟɬ ɜɵɩɨɥɧɹɬɶɫɹ ɞɨ ɞɨɫɬɢɠɟɧɢɹ ɬɨɱɤɢ ɨɫɬɚɧɨɜɚ. Ʉɨɝɞɚ ɞɨɫɬɢɝɧɭɬɚ ɬɨɱɤɚ ɨɫɬɚɧɨɜɚ, ɨɬɤɪɵɜɚɟɬɫɹ ɩɟɪɫɩɟɤɬɢɜɚ Debug, ɢ ɜɵɩɨɥɧɟɧɢɟ ɩɪɢɨɫɬɚɧɚɜɥɢɜɚɟɬɫɹ. Ɂɚɦɟɬɶɬɟ, ɱɬɨ ɩɪɨɰɟɫɫ ɜɫɟ ɟɳɟ ɚɤɬɢɜɟɧ (ɧɟ ɩɪɟɪɜɚɧ) ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Debug. Ⱦɪɭɝɢɟ ɧɢɬɢ ɦɨɝɭɬ ɜɫɟ ɟɳɟ ɜɵɩɨɥɧɹɬɶɫɹ.
44
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
6. ȼ ɪɟɞɚɤɬɨɪɟ ɜ ɩɟɪɫɩɟɤɬɢɜɟ Debug ɜɵɛɟɪɢɬɟ new Vector() ɢɡ ɫɬɪɨɤɢ, ɧɚɞ ɤɨɬɨɪɨɣ ɡɚɞɚɧɚ ɬɨɱɤɚ ɨɫɬɚɧɨɜɚ, ɚ ɢɡ ɟɟ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜɵɛɟɪɢɬɟ Inspect.
7. ȼɵɪɚɠɟɧɢɟ ɜɵɱɢɫɥɹɟɬɫɹ ɜ ɤɨɧɬɟɤɫɬɟ ɬɟɤɭɳɟɝɨ ɫɬɟɤɚ ɢ ɩɨɹɜɥɹɟɬɫɹ ɜɫɩɥɵɜɚɸɳɟɟ ɨɬɨɛɪɚɠɟɧɢɟ ɪɟɡɭɥɶɬɚɬɨɜ. Ɇɨɠɧɨ ɩɨɫɥɚɬɶ ɪɟɡɭɥɶɬɚɬ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɟ Expressions ɧɚɠɚɬɢɟɦ ɤɥɚɜɢɲ Ctrl+Shift+I. 8. ȼɵɪɚɠɟɧɢɹ, ɤɨɬɨɪɵɟ ɜɵɱɢɫɥɹɸɬɫɹ ɩɪɢ ɨɬɥɚɞɤɟ, ɛɭɞɭɬ ɩɟɪɟɱɢɫɥɟɧɵ ɜ ɷɬɨɦ ɩɪɟɞɫɬɚɜɥɟɧɢɢ. ɑɬɨɛɵ ɭɞɚɥɢɬɶ ɜɵɪɚɠɟɧɢɟ ɩɨɫɥɟ ɪɚɛɨɬɵ ɫ ɧɢɦ, ɜɵɛɟɪɢɬɟ ɜɵɪɚɠɟɧɢɟ ɢ ɜɵɛɟɪɢɬɟ Remove ɢɡ ɟɝɨ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ. 9. ɉɪɟɞɫɬɚɜɥɟɧɢɟ Variables, ɤɨɬɨɪɨɟ ɞɨɫɬɭɩɧɨ ɧɚ ɡɚɤɥɚɞɤɟ ɜɦɟɫɬɟ ɫ ɩɪɟɞɫɬɚɜɥɟɧɢɟɦ Expressions, ɨɬɨɛɪɚɠɚɟɬ ɡɧɚɱɟɧɢɹ ɩɟɪɟɦɟɧɧɵɯ ɜ ɜɵɛɪɚɧɧɨɦ ɫɬɟɤɟ. Ɋɚɫɤɪɵɜɚɣɬɟ ɞɟɪɟɜɨ fFull ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Variables, ɩɨɤɚ ɧɟ ɭɜɢɞɢɬɟ elementCount. 10. ɉɟɪɟɦɟɧɧɵɟ, ɜ ɱɚɫɬɧɨɫɬɢ elementCount ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Variables ɛɭɞɭɬ ɢɡɦɟɧɟɧɵ, ɤɨɝɞɚ ɛɭɞɟɬ ɨɫɭɳɟɫɬɜɥɟɧ ɩɟɪɟɯɨɞ ɱɟɪɟɡ ɤɨɞ VectorTest ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɟ Debug, ɞɥɹ ɷɬɨɝɨ ɧɚɞɨ ɳɟɥɤɧɭɬɶ ɧɚ ɤɧɨɩɤɟ Step Over. ȼɵɩɨɥɧɟɧɢɟ ɩɪɨɞɨɥɠɢɬɫɹ ɫɨ ɫɥɟɞɭɸɳɟɣ ɫɬɪɨɤɢ 45
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɬɨɝɨ ɠɟ (ɢɥɢ, ɟɫɥɢ ɧɚɯɨɞɢɬɟɫɶ ɜ ɤɨɧɰɟ ɦɟɬɨɞɚ, ɜ ɬɨɦ ɦɟɬɨɞɟ, ɢɡ ɤɨɬɨɪɨɝɨ ɬɟɤɭɳɢɣ ɦɟɬɨɞ ɛɵɥ ɜɵɡɜɚɧ).
11. ɉɨɩɪɨɛɭɣɬɟ ɧɟɤɨɬɨɪɵɟ ɞɪɭɝɢɟ ɤɧɨɩɤɢ ɲɚɝɨɜ (Step Into, Step Return), ɱɬɨɛɵ ɩɨ ɲɚɝɚɦ ɩɪɨɣɬɢ ɱɟɪɟɡ ɤɨɞ. Ɂɚɦɟɬɶɬɟ ɪɚɡɧɢɰɭ ɜ ɩɪɢɟɦɚɯ ɩɨɲɚɝɨɜɨɝɨ ɜɵɩɨɥɧɟɧɢɹ. 12. Ɇɨɠɧɨ ɡɚɤɨɧɱɢɬɶ ɫɟɚɧɫ ɨɬɥɚɞɤɢ, ɪɚɡɪɟɲɢɜ ɩɪɨɝɪɚɦɦɟ ɜɵɩɨɥɧɢɬɶɫɹ ɞɨ ɤɨɧɰɚ ɢɥɢ ɩɪɟɪɜɚɜ ɟɟ. x Ɇɨɠɧɨ ɩɪɨɞɨɥɠɢɬɶ ɩɨɲɚɝɨɜɨɟ ɜɵɩɨɥɧɟɧɢɟ ɤɨɞɚ ɩɪɢ ɩɨɦɨɳɢ ɤɧɨɩɨɤ Step, ɩɨɤɚ ɩɪɨɝɪɚɦɦɚ ɧɟ ɡɚɤɨɧɱɢɬɫɹ. x Ɇɨɠɧɨ ɳɟɥɤɧɭɬɶ ɧɚ ɤɧɨɩɤɟ Resume, ɱɬɨɛɵ ɪɚɡɪɟɲɢɬɶ ɩɪɨɝɪɚɦɦɟ ɜɵɩɨɥɧɹɬɶɫɹ ɞɨ ɫɥɟɞɭɸɳɟɣ ɬɨɱɤɢ ɨɫɬɚɧɨɜɚ ɢɥɢ ɞɨ ɡɚɜɟɪɲɟɧɢɹ ɩɪɨɝɪɚɦɦɵ. x Ɇɨɠɧɨ ɜɵɛɪɚɬɶ Terminate ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɩɪɨɰɟɫɫɚ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Debug, ɱɬɨɛɵ ɩɪɟɪɜɚɬɶ ɩɪɨɝɪɚɦɦɭ. 6.1. ȼɵɱɢɫɥɟɧɢɟ ɜɵɪɚɠɟɧɢɣ Ɋɚɫɫɦɨɬɪɢɦ, ɤɚɤ ɜɵɱɢɫɥɹɬɶ ɜɵɪɚɠɟɧɢɹ ɜ ɤɨɧɬɟɤɫɬɟ ɜɵɩɨɥɧɹɸɳɟɣɫɹ Javaɩɪɨɝɪɚɦɦɵ. 1. Ɉɬɥɚɞɶɬɟ junit.samples.VectorTest.java ɞɨ ɬɨɱɤɢ ɨɫɬɚɧɨɜɚ ɜ ɦɟɬɨɞɟ setUp() ɢ ɜɵɛɟɪɢɬɟ Step Over ɞɜɚɠɞɵ, ɱɬɨɛɵ ɡɚɩɨɥɧɢɬɶ fFull. 2. Ɉɬɤɪɨɣɬɟ ɩɪɟɞɫɬɚɜɥɟɧɢɟ Display, ɜɵɛɪɚɜ Window > Show View > Display ɢ ɜɜɟɞɢɬɟ ɫɥɟɞɭɸɳɭɸ ɫɬɪɨɤɭ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɟ: fFull.size()
3. ȼɵɛɟɪɢɬɟ ɜɜɟɞɟɧɧɵɣ ɬɟɤɫɬ ɢ ɢɡ ɟɝɨ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɜɵɛɟɪɢɬɟ Display. Ɇɨɠɧɨ ɬɚɤɠɟ ɜɵɛɪɚɬɶ Display Result of Evaluating Selected Text ɢɡ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Display.
4. ȼɵɪɚɠɟɧɢɟ ɜɵɱɢɫɥɹɟɬɫɹ, ɢ ɪɟɡɭɥɶɬɚɬ ɨɬɨɛɪɚɠɚɟɬɫɹ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Display.
5. ɇɚ ɧɨɜɨɣ ɫɬɪɨɤɟ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Display ɜɜɟɞɢɬɟ ɫɥɟɞɭɸɳɭɸ ɫɬɪɨɤɭ: 46
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
fFull.toArray()
6. ȼɵɛɟɪɢɬɟ ɷɬɭ ɫɬɪɨɤɭ ɢ ɜɵɛɟɪɢɬɟ Inspect ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ. Ɇɨɠɧɨ ɬɚɤɠɟ ɜɵɛɪɚɬɶ Inspect Result of Evaluating Selected Text ɢɡ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Display. 7. Ɉɬɤɪɨɟɬɫɹ ɭɩɪɨɳɟɧɧɨɟ ɨɤɧɨ ɫɨ ɡɧɚɱɟɧɢɟɦ ɜɵɱɢɫɥɟɧɧɨɝɨ ɜɵɪɚɠɟɧɢɹ.
6.2. ȼɵɱɢɫɥɟɧɢɟ ɮɪɚɝɦɟɧɬɨɜ Ⱦɚɥɟɟ ɛɭɞɟɦ ɜɵɱɢɫɥɹɬɶ ɜɵɪɚɠɟɧɢɹ Java, ɢɫɩɨɥɶɡɭɹ scrapbook – ɪɚɛɨɱɢɣ ɛɭɮɟɪ Java. ɋɬɪɚɧɢɰɵ ɪɚɛɨɱɟɝɨ ɛɭɮɟɪɚ Java ɩɨɡɜɨɥɹɸɬ ɷɤɫɩɟɪɢɦɟɧɬɢɪɨɜɚɬɶ ɫ ɮɪɚɝɦɟɧɬɚɦɢ ɤɨɞɚ Java ɩɟɪɟɞ ɩɨɦɟɳɟɧɢɟɦ ɢɯ ɜ ɩɪɨɝɪɚɦɦɭ. 1. ȼ ɦɟɧɸ File ɜɵɛɟɪɢɬɟ New > Other > Java > Java Run/Debug > Scrapbook Page ɢ ɩɨɥɭɱɢɬɟ ɩɪɢɝɥɚɲɟɧɢɟ ɜɵɛɪɚɬɶ ɰɟɥɟɜɨɣ ɤɚɬɚɥɨɝ ɞɥɹ ɫɬɪɚɧɢɰɵ.
2. ȼ ɩɨɥɟ Enter or select the folder ɜɜɟɞɢɬɟ ɢɥɢ ɧɚɣɞɢɬɟ ɜ ɩɪɨɫɦɨɬɪɟ ɤɨɪɧɟɜɨɣ ɤɚɬɚɥɨɝ ɩɪɨɟɤɬɚ JUnit. 3. ȼ ɩɨɥɟ File name ɜɜɟɞɢɬɟ MyScrap. 4. Ʉɨɝɞɚ ɡɚɤɨɧɱɢɬɟ, ɳɟɥɤɧɢɬɟ ɧɚ Finish. ɋɨɡɞɚɟɬɫɹ ɫɬɪɚɧɢɰɚ ɪɚɛɨɱɟɝɨ ɛɭɮɟɪɚ ɫ ɪɚɫɲɢɪɟɧɢɟɦ ɢɦɟɧɢ ɮɚɣɥɚ jpage, ɤɨɬɨɪɨɟ ɛɭɞɟɬ ɞɨɛɚɜɥɟɧɨ ɚɜɬɨɦɚɬɢɱɟɫɤɢ, ɟɫɥɢ ɟɝɨ ɧɟ ɜɜɟɥɢ. ɋɬɪɚɧɢɰɚ ɪɚɛɨɱɟɝɨ ɛɭɮɟɪɚ ɚɜɬɨɦɚɬɢɱɟɫɤɢ ɨɬɤɪɵɜɚɟɬɫɹ ɜ ɪɟɞɚɤɬɨɪɟ.
47
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
5. ȼ ɪɟɞɚɤɬɨɪɟ ɜɜɟɞɢɬɟ System.get, ɡɚɬɟɦ ɢɫɩɨɥɶɡɭɣɬɟ ɤɨɧɬɟɧɬɧɭɸ ɩɨɦɨɳɶ – Ctrl+Space ɞɥɹ ɡɚɜɟɪɲɟɧɢɹ ɮɪɚɝɦɟɧɬɚ ɤɚɤ System.getProperties().
6. ȼɵɞɟɥɢɬɟ ɜɫɸ ɧɚɩɟɱɚɬɚɧɧɭɸ ɫɬɪɨɤɭ ɢ ɜɵɛɟɪɢɬɟ Display ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ. Ɇɨɠɧɨ ɬɚɤɠɟ ɜɵɛɪɚɬɶ Display Result of Evaluating Selected Text ɢɡ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ.
7. Ʉɨɝɞɚ ɜɵɱɢɫɥɟɧɢɟ ɡɚɤɨɧɱɢɬɫɹ, ɪɟɡɭɥɶɬɚɬ ɜɵɱɢɫɥɟɧɢɹ ɛɭɞɟɬ ɜɵɞɟɥɟɧ ɢ ɨɬɨɛɪɚɠɟɧ ɜ ɫɬɪɚɧɢɰɟ ɪɚɛɨɱɟɝɨ ɛɭɮɟɪɚ. 8. Ɇɨɠɧɨ ɩɪɨɢɧɫɩɟɤɬɢɪɨɜɚɬɶ ɪɟɡɭɥɶɬɚɬ ɜɵɱɢɫɥɟɧɢɹ, ɜɵɛɪɚɜ ɬɟɤɫɬ ɢ ɜɵɛɪɚɜ Inspect ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ ɢɥɢ ɜɵɛɪɚɜ Inspect Result of Evaluating Selected Text ɢɡ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ. 9. ɉɨɫɥɟ ɜɵɱɢɫɥɟɧɢɹ ɮɪɚɝɦɟɧɬɚ ɤɨɞɚ ɜ ɫɬɪɚɧɢɰɟ ɪɚɛɨɱɟɝɨ ɛɭɮɟɪɚ ɦɨɠɧɨ ɡɚɤɪɵɬɶ ɪɟɞɚɤɬɨɪ. Ⱦɥɹ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɮɪɚɝɦɟɧɬɚ ɜ ɛɭɞɭɳɟɦ ɧɚɞɨ ɫɨɯɪɚɧɢɬɶ ɢɡɦɟɧɟɧɢɹ ɜ ɫɬɪɚɧɢɰɟ. 7. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɩɟɪɫɩɟɤɬɢɜɵ Java Browsing Ⱦɚɥɟɟ ɪɚɫɫɦɨɬɪɢɦ ɢɫɩɨɥɶɡɨɜɚɧɢɟ ɩɟɪɫɩɟɤɬɢɜɵ Java browsing ɞɥɹ ɩɪɨɫɦɨɬɪɚ ɤɨɞɚ ɢ ɦɚɧɢɩɭɥɢɪɨɜɚɧɢɹ ɢɦ. ȼ ɨɬɥɢɱɢɟ ɨɬ Package Explorer, ɤɨɬɨɪɵɣ ɨɪɝɚɧɢɡɭɟɬ ɷɥɟɦɟɧɬɵ Java ɜ ɞɟɪɟɜɨ, ɫɨɫɬɨɹɳɟɟ ɢɡ ɩɪɨɟɤɬɨɜ, 48
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɩɚɤɟɬɨɜ, ɤɨɦɩɢɥɢɪɭɟɦɵɯ ɦɨɞɭɥɟɣ, ɬɢɩɨɜ ɢ ɬ.ɞ., ɩɟɪɫɩɟɤɬɢɜɚ ɩɪɨɫɦɨɬɪɚ ɢɫɩɨɥɶɡɭɟɬ ɪɚɡɧɵɟ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɞɥɹ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɬɨɣ ɠɟ ɢɧɮɨɪɦɚɰɢɢ. ȼɵɛɨɪ ɷɥɟɦɟɧɬɚ ɜ ɨɞɧɨɦ ɩɪɟɞɫɬɚɜɥɟɧɢɢ ɩɨɤɚɠɟɬ ɟɝɨ ɫɨɞɟɪɠɢɦɨɟ ɜ ɞɪɭɝɨɦ ɩɪɟɞɫɬɚɜɥɟɧɢɢ. ɑɬɨɛɵ ɨɬɤɪɵɬɶ ɩɟɪɫɩɟɤɬɢɜɭ ɩɪɨɫɦɨɬɪɚ, ɚɤɬɢɜɢɡɢɪɭɣɬɟ Window > Open Perspective > Java Browsing ɢɡ ɩɟɪɫɩɟɤɬɢɜɵ Java ɢɥɢ ɢɫɩɨɥɶɡɭɣɬɟ ɤɨɧɬɟɤɫɬɧɨɟ ɦɟɧɸ ɤɧɨɩɤɢ Open a Perspective ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ.
ɉɪɟɞɫɬɚɜɥɟɧɢɹ ɩɟɪɫɩɟɤɬɢɜɵ ɫɨɟɞɢɧɹɸɬɫɹ ɞɪɭɝ ɫ ɞɪɭɝɨɦ ɪɚɡɧɵɦɢ ɩɭɬɹɦɢ: x ȼɵɛɨɪ ɷɥɟɦɟɧɬɚ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Projects ɩɨɤɚɡɵɜɚɟɬ ɟɝɨ ɩɚɤɟɬɵ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Packages. x ɉɪɟɞɫɬɚɜɥɟɧɢɟ Types ɩɨɤɚɡɵɜɚɟɬ ɬɢɩɵ, ɫɨɞɟɪɠɚɳɢɟɫɹ ɜ ɩɚɤɟɬɟ, ɜɵɛɪɚɧɧɨɦ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Packages. x ɉɪɟɞɫɬɚɜɥɟɧɢɟ Members ɩɨɤɚɡɵɜɚɟɬ ɱɥɟɧɵ ɜɵɛɪɚɧɧɨɝɨ ɬɢɩɚ. Ɏɭɧɤɰɢɨɧɚɥɶɧɨ ɩɪɟɞɫɬɚɜɥɟɧɢɟ Members ɫɪɚɜɧɢɦɨ ɫ ɩɪɟɞɫɬɚɜɥɟɧɢɟɦ Outline, ɢɫɩɨɥɶɡɭɟɦɵɦ ɜ ɨɛɵɱɧɨɣ ɩɟɪɫɩɟɤɬɢɜɟ Java. x ȼɵɛɨɪ ɷɥɟɦɟɧɬɚ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Members ɨɬɤɪɵɜɚɟɬ ɷɥɟɦɟɧɬ ɜ ɪɟɞɚɤɬɨɪɟ. ȿɫɥɢ ɪɟɞɚɤɬɨɪ ɞɥɹ ɷɥɟɦɟɧɬɚ ɧɟ ɨɬɤɪɵɬ, ɞɜɨɣɧɨɣ ɳɟɥɱɨɤ ɧɚ ɷɥɟɦɟɧɬɟ ɨɬɤɪɨɟɬ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɣ ɪɟɞɚɤɬɨɪ. ȼɫɟ ɱɟɬɵɪɟ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɩɨ ɭɦɨɥɱɚɧɢɸ ɫɜɹɡɚɧɵ ɫ ɚɤɬɢɜɧɵɦ ɪɟɞɚɤɬɨɪɨɦ. ɗɬɨ ɨɡɧɚɱɚɟɬ, ɱɬɨ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɛɭɞɭɬ ɫɨɝɥɚɫɨɜɵɜɚɬɶ ɫɜɨɟ ɫɨɞɟɪɠɢɦɨɟ ɢ ɜɵɛɨɪ ɜ ɧɢɯ ɜ ɫɨɨɬɜɟɬɫɬɜɢɢ ɫ ɮɚɣɥɨɦ, ɩɪɟɞɫɬɚɜɥɟɧɧɵɦ ɜ ɚɤɬɢɜɧɨɦ ɪɟɞɚɤɬɨɪɟ. ɋɥɟɞɭɸɳɢɟ ɲɚɝɢ ɢɥɥɸɫɬɪɢɪɭɸɬ ɬɚɤɨɟ ɩɨɜɟɞɟɧɢɟ: 1. ȼɵɛɟɪɢɬɟ junit.extensions ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Packages. 2. Ɉɬɤɪɨɣɬɟ ɬɢɩ TestSetup ɜ ɪɟɞɚɤɬɨɪɟ ɞɜɨɣɧɵɦ ɳɟɥɱɤɨɦ ɧɚ ɧɟɦ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Types view. 49
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
3. Ɍɟɩɟɪɶ ɜɟɪɧɢɬɟ ɮɨɤɭɫ ɧɚ ɪɟɞɚɤɬɨɪ, ɨɬɤɪɵɬɵɣ ɧɚ ɮɚɣɥɟ TestCase.java, ɳɟɥɤɧɭɜ ɧɚ ɡɚɤɥɚɞɤɟ ɪɟɞɚɤɬɨɪɚ. ɉɪɟɞɫɬɚɜɥɟɧɢɹ Packages, Types ɢ Members ɫɨɝɥɚɫɨɜɚɥɢ ɫɜɨɟ ɫɨɞɟɪɠɢɦɨɟ ɢ ɜɵɛɨɪɵ ɞɥɹ ɨɬɪɚɠɟɧɢɹ ɚɤɬɢɜɧɨɝɨ ɪɟɞɚɤɬɨɪɚ. ȼɵɛɨɪ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Packages ɭɫɬɚɧɨɜɥɟɧ ɧɚ junit.framework, ɚ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ Types ɩɨɤɚɡɵɜɚɟɬɫɹ ɫɨɞɟɪɠɢɦɨɟ ɩɚɤɟɬɨɜ junit.framework. Ʉɪɨɦɟ ɬɨɝɨ, ɜɵɛɪɚɧ ɬɢɩ TestCase. Ɏɭɧɤɰɢɨɧɚɥɶɧɨ ɩɟɪɫɩɟɤɬɢɜɚ Java ȼrowsing ɩɨɥɧɨɫɬɶɸ ɫɪɚɜɧɢɦɚ ɫ ɩɟɪɫɩɟɤɬɢɜɨɣ Java. Ʉɨɧɬɟɤɫɬɧɵɟ ɦɟɧɸ ɞɥɹ ɩɪɨɟɤɬɨɜ, ɩɚɤɟɬɨɜ, ɬɢɩɨɜ ɢ ɬ.ɞ. ɢ ɨɛɳɟɟ ɦɟɧɸ ɢ ɩɚɧɟɥɶ ɢɧɫɬɪɭɦɟɧɬɨɜ ɬɟ ɠɟ ɫɚɦɵɟ. ɋɥɟɞɨɜɚɬɟɥɶɧɨ, ɚɤɬɢɜɢɡɚɰɢɹ ɷɬɢɯ ɮɭɧɤɰɢɣ ɚɧɚɥɨɝɢɱɧɚ ɚɤɬɢɜɢɡɚɰɢɢ ɢɯ ɜ ɩɟɪɫɩɟɤɬɢɜɟ Java. 8. ɇɚɩɢɫɚɧɢɟ ɢ ɜɵɩɨɥɧɟɧɢɟ ɬɟɫɬɨɜ JUnit Ⱦɚɥɟɟ ɛɭɞɟɦ ɢɫɩɨɥɶɡɨɜɚɬɶ ɬɟɫɬɨɜɵɣ ɤɚɪɤɚɫ JUnit ɞɥɹ ɧɚɩɢɫɚɧɢɹ ɢ ɜɵɩɨɥɧɟɧɢɹ ɬɟɫɬɨɜ. ɉɪɟɠɞɟ ɱɟɦ ɩɢɫɚɬɶ ɬɟɫɬɵ JUnit ɧɟɨɛɯɨɞɢɦɨ ɞɨɛɚɜɢɬɶ ɛɢɛɥɢɨɬɟɤɭ junit.jar ɤ ɦɚɪɲɪɭɬɭ ɩɨɫɬɪɨɟɧɢɹ. ɂɧɫɬɚɥɥɹɰɢɹ Eclipse ɜɤɥɸɱɚɟɬ ɜ ɫɟɛɹ JUnit ɜ ɩɨɞɤɥɸɱɟɧɢɢ org.junit: 1. ɋɨɡɞɚɣɬɟ ɩɪɨɟɤɬ JUnitTest 2. Ɉɬɤɪɨɣɬɟ ɫɬɪɚɧɢɰɭ ɧɚɫɬɪɨɣɤɢ ɦɚɪɲɪɭɬɚ ɩɨɫɬɪɨɟɧɢɹ ɩɪɨɟɤɬɚ – ɜ ɤɨɧɬɟɤɫɬɧɨɦ ɦɟɧɸ ɩɪɨɟɤɬɚ ɜɵɛɟɪɢɬɟ Properties > Java Build Path 3. ɉɟɪɟɤɥɸɱɢɬɟɫɶ ɧɚ ɡɚɤɥɚɞɤɭ Libraries ɢ ɧɚɠɦɢɬɟ ɤɧɨɩɤɭ Add Library… 4. ȼ ɩɨɹɜɢɜɲɟɦɫɹ ɨɤɧɟ ɜɵɛɟɪɢɬɟ JUnit ɢ ɧɚɠɦɢɬɟ Next > 5. ȼ ɫɥɟɞɭɸɳɟɦ ɨɤɧɟ ɜɵɛɟɪɢɬɟ ɜɟɪɫɢɸ ɛɢɛɥɢɨɬɟɤɢ JUnit 3.8.1 ɢ ɧɚɠɦɢɬɟ Finish. Ȼɭɞɟɬ ɞɨɛɚɜɥɟɧɚ ɛɢɛɥɢɨɬɟɤɚ ɫɨɞɟɪɠɚɳɚɹ junit.jar ɢɡ org.junit_3.8.1, ɜ ɤɨɬɨɪɨɦ ɫɨɞɟɪɠɢɬɫɹ ɚɪɯɢɜ ɢɫɯɨɞɧɨɝɨ ɤɨɞɚ junitsrc.zip. ɇɚɠɦɢɬɟ Ok. Ɍɟɩɟɪɶ, ɤɨɝɞɚ ɩɪɨɟɤɬ JUnitTest ɢɦɟɟɬ ɞɨɫɬɭɩ ɤ ɤɥɚɫɫɚɦ Junit, ɦɨɠɧɨ ɩɢɫɚɬɶ ɬɟɫɬ. Ɋɟɚɥɢɡɭɟɦ ɬɟɫɬ ɤɚɤ ɩɨɞɤɥɚɫɫ TestCase. Ɇɨɠɧɨ ɫɞɟɥɚɬɶ ɷɬɨ ɥɢɛɨ ɢɫɩɨɥɶɡɭɹ ɫɬɚɧɞɚɪɬɧɵɣ Ɇɚɫɬɟɪ Class, ɥɢɛɨ ɫɩɟɰɢɚɥɶɧɵɣ Ɇɚɫɬɟɪ Test Case: 1. Ɉɬɤɪɨɣɬɟ Ɇɚɫɬɟɪ New (File > New > JUnit Test Case). 2. ȼɜɟɞɢɬɟ ɢɦɹ ɜɚɲɟɝɨ ɤɥɚɫɫɚ ɬɟɫɬɚ TestFailure:
50
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
3. ɓɟɥɤɧɢɬɟ ɧɚ Finish ɞɥɹ ɫɨɡɞɚɧɢɹ ɤɥɚɫɫɚ ɬɟɫɬɚ. Ⱦɨɛɚɜɶɬɟ ɦɟɬɨɞ ɬɟɫɬɢɪɨɜɚɧɢɹ ɜ ɤɥɚɫɫ TestFailure. Ȼɵɫɬɪɵɣ ɫɩɨɫɨɛ ɫɨɡɞɚɧɢɹ ɬɟɫɬɨɜɨɝɨ ɦɟɬɨɞɚ – ɩɪɢ ɩɨɦɨɳɢ ɲɚɛɥɨɧɚ test. ɑɬɨɛɵ ɷɬɨ ɫɞɟɥɚɬɶ, ɜɜɟɞɢɬɟ test ɢ Ctrl+Space ɞɥɹ ɚɤɬɢɜɢɡɚɰɢɢ ɤɨɧɬɟɧɬɧɨɣ ɩɨɦɨɳɢ ɢ ɜɵɛɟɪɢɬɟ ɲɚɛɥɨɧ test. ɂɡɦɟɧɢɬɟ ɢɦɹ ɫɨɡɞɚɜɚɟɦɨɝɨ ɦɟɬɨɞɚ ɧɚ testFailure ɢ ɜɵɡɨɜɢɬɟ ɦɟɬɨɞ fail(). Ɍɚɤɠɟ ɢɡɦɟɧɢɬɟ ɦɨɞɢɮɢɤɚɬɨɪ ɜɢɞɢɦɨɫɬɢ, ɱɬɨɛɵ ɷɬɨɬ ɦɟɬɨɞ ɬɟɫɬɢɪɨɜɚɧɢɹ ɛɵɥ ɨɬɤɪɵɬɵɦ. public void testFailure(){ fail(); }
8.1. ȼɵɩɨɥɧɟɧɢɟ ɬɟɫɬɨɜ ɑɬɨɛɵ ɡɚɩɭɫɬɢɬɶ TestFailure, ɚɤɬɢɜɢɡɢɪɭɣɬɟ ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɢ ɜɵɛɟɪɢɬɟ Run as > JUnit Test. Ɇɨɠɧɨ ɩɪɨɢɧɫɩɟɤɬɢɪɨɜɚɬɶ ɪɟɡɭɥɶɬɚɬɵ ɬɟɫɬɚ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ JUnit. ɗɬɨ ɩɪɟɞɫɬɚɜɥɟɧɢɟ ɩɨɤɚɡɵɜɚɟɬ ɯɨɞ ɜɵɩɨɥɧɟɧɢɹ ɢ ɫɨɫɬɨɹɧɢɟ ɬɟɫɬɚ:
51
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɉɪɟɞɫɬɚɜɥɟɧɢɟ ɩɨɤɚɡɵɜɚɟɬɫɹ ɜ ɬɟɤɭɳɟɣ ɩɟɪɫɩɟɤɬɢɜɟ, ɤɨɝɞɚ ɛɵ ɧɢ ɛɵɥɨ ɡɚɩɭɳɟɧɨ ɜɵɩɨɥɧɟɧɢɟ ɬɟɫɬɚ. ɉɪɟɞɫɬɚɜɥɟɧɢɟ JUnit ɢɦɟɟɬ ɞɜɟ ɡɚɤɥɚɞɤɢ: ɨɞɧɚ ɩɨɤɚɡɵɜɚɟɬ ɤɨɦɩɥɟɤɬ ɬɟɫɬɚ ɜ ɜɢɞɟ ɞɟɪɟɜɚ, ɚ ɞɪɭɝɚɹ ɩɨɤɚɡɵɜɚɟɬ ɫɩɢɫɨɤ ɨɲɢɛɨɤ. Ɇɨɠɧɨ ɩɟɪɟɯɨɞɢɬɶ ɨɬ ɨɲɢɛɤɢ ɤ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɦɭ ɢɫɯɨɞɧɨɦɭ ɤɨɞɭ ɞɜɨɣɧɵɦ ɳɟɥɱɤɨɦ ɧɚ ɫɨɨɬɜɟɬɫɬɜɭɸɳɟɣ ɫɬɪɨɤɟ ɜ ɬɪɚɫɫɟ ɨɲɢɛɤɢ. ɉɨɧɢɦɚɹ JUnit ɤɚɤ ɛɵɫɬɪɨɟ ɩɪɟɞɫɬɚɜɥɟɧɢɟ, ɭɞɚɥɢɬɟ ɨɩɟɪɚɬɨɪ fail() ɜ ɦɟɬɨɞɟ testFailure(), ɜ ɷɬɨɦ ɫɥɭɱɚɟ ɬɟɫɬ ɨɛɯɨɞɢɬɫɹ, ɢ ɩɟɪɟɡɚɩɭɫɬɢɬɟ ɬɟɫɬ ɫɧɨɜɚ. ɗɬɨ ɦɨɠɧɨ ɫɞɟɥɚɬɶ ɥɢɛɨ ɳɟɥɤɧɭɜ ɧɚ ɤɧɨɩɤɟ Rerun Last Text ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ ɩɪɟɞɫɬɚɜɥɟɧɢɹ, ɥɢɛɨ ɩɟɪɟɡɚɩɭɫɬɢɜ ɩɪɨɝɪɚɦɦɭ, ɤɨɬɨɪɚɹ ɛɵɥɚ ɡɚɩɭɳɟɧɚ ɩɨɫɥɟɞɧɟɣ ɚɤɬɢɜɢɡɚɰɢɟɣ ɜɵɩɚɞɚɸɳɟɝɨ Run. ȼ ɩɨɫɥɟɞɧɟɦ ɫɥɭɱɚɟ ɬɟɫɬ ɭɫɩɟɲɟɧ. ɂɧɞɢɤɚɬɨɪ ɭɫɩɟɲɧɨɫɬɢ ɩɨɤɚɡɵɜɚɟɬɫɹ ɧɚ ɢɤɨɧɤɟ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Junit, ɚ ɫɬɪɨɤɚ ɫɨɫɬɨɹɧɢɹ ɩɨɤɚɡɵɜɚɟɬ ɪɟɡɭɥɶɬɚɬ ɬɟɫɬɚ. ɍɫɩɟɲɧɵɣ ɡɚɩɭɫɤ ɬɟɫɬɚ. ɍɫɩɟɲɧɵɣ ɡɚɩɭɫɤ ɬɟɫɬɚ, ɧɨ ɫɨɞɟɪɠɢɦɨɟ ɪɚɛɨɱɟɝɨ ɦɟɫɬɚ ɛɵɥɨ ɢɡɦɟɧɟɧɨ ɩɨɫɥɟ ɩɨɫɥɟɞɧɟɝɨ ɡɚɩɭɫɤɚ. Ʉɪɨɦɟ ɜɵɩɨɥɧɟɧɢɹ ɬɟɫɬɚ, ɨɩɢɫɚɧɧɨɝɨ ɜɵɲɟ, ɦɨɠɧɨ: 1. ȼɵɩɨɥɧɹɬɶ ɬɟɫɬ ɜ ɩɪɨɟɤɬɟ, ɢɫɯɨɞɧɨɣ ɩɚɩɤɟ ɢɥɢ ɩɚɤɟɬɟ. Ⱦɥɹ ɷɬɨɝɨ ɜɵɛɟɪɢɬɟ ɩɪɨɟɤɬ, ɩɚɤɟɬ ɢɥɢ ɢɫɯɨɞɧɭɸ ɩɚɩɤɭ ɢ ɡɚɩɭɫɬɢɬɟ ɜɫɟ ɜɤɥɸɱɟɧɧɵɟ ɬɟɫɬɵ ɩɪɢ ɩɨɦɨɳɢ Run as > JUnit Test. ɗɬɚ ɤɨɦɚɧɞɚ 52
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɧɚɯɨɞɢɬ ɜɫɟ ɬɟɫɬɵ ɜɧɭɬɪɢ ɩɪɨɟɤɬɚ, ɢɫɯɨɞɧɨɣ ɩɚɩɤɢ ɢɥɢ ɩɚɤɟɬɚ ɢ ɜɵɩɨɥɧɹɟɬ ɢɯ. 2. ȼɵɩɨɥɧɹɬɶ ɟɞɢɧɫɬɜɟɧɧɵɣ ɦɟɬɨɞ ɬɟɫɬɚ. Ⱦɥɹ ɷɬɨɝɨ ɜɵɛɟɪɢɬɟ ɦɟɬɨɞ ɬɟɫɬɚ ɜ Outline ɢɥɢ Package Explorer ɢ ɩɪɢ ɩɨɦɨɳɢ Run as > JUnit Test ɜɵɛɪɚɧɧɵɣ ɦɟɬɨɞ ɛɭɞɟɬ ɜɵɩɨɥɧɟɧ. 3. ȼɵɩɨɥɧɹɬɶ ɟɞɢɧɫɬɜɟɧɧɵɣ ɬɟɫɬ. Ⱦɥɹ ɷɬɨɝɨ ɜɵɛɟɪɢɬɟ ɬɟɫɬ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ JUnit ɢ ɜɵɩɨɥɧɢɬɟ Rerun ɢɡ ɤɨɧɬɟɤɫɬɧɨɝɨ ɦɟɧɸ. 8.2. ɇɚɫɬɪɨɣɤɚ ɤɨɧɮɢɝɭɪɚɰɢɢ ɬɟɫɬɚ ȿɫɥɢ ɧɟɨɛɯɨɞɢɦɨ ɩɟɪɟɞɚɬɶ ɩɚɪɚɦɟɬɪɵ ɢɥɢ ɧɚɫɬɪɨɢɬɶ ɭɫɬɚɧɨɜɤɢ ɞɥɹ ɜɵɩɨɥɧɟɧɢɹ ɬɟɫɬɚ, ɨɬɤɪɨɣɬɟ ɞɢɚɥɨɝ Launch Configuration. ȼɵɛɟɪɢɬɟ Run... ɜ ɜɵɩɚɞɚɸɳɟɦ ɦɟɧɸ Run ɜ ɩɚɧɟɥɢ ɢɧɫɬɪɭɦɟɧɬɨɜ:
ȼ ɷɬɨɦ ɞɢɚɥɨɝɟ ɦɨɠɧɨ ɡɚɞɚɬɶ ɜɵɩɨɥɧɹɟɦɵɣ ɬɟɫɬ, ɟɝɨ ɚɪɝɭɦɟɧɬɵ, classpath ɦɨɦɟɧɬɚ ɜɵɩɨɥɧɟɧɢɹ ɢ ɫɪɟɞɭ Java ɦɨɦɟɧɬɚ ɜɵɩɨɥɧɟɧɢɹ. 8.3. Ɉɬɥɚɞɤɚ ɨɲɢɛɨɤ ɬɟɫɬɚ ȼ ɫɥɭɱɚɟ ɨɲɢɛɤɢ ɬɟɫɬɚ ɦɨɠɧɨ ɫɥɟɞɨɜɚɬɶ ɬɚɤɢɦ ɲɚɝɚɦ ɞɥɹ ɟɝɨ ɨɬɥɚɞɤɢ: 1. ɓɟɥɤɧɢɬɟ ɞɜɚɠɞɵ ɧɚ ɷɥɟɦɟɧɬɟ ɨɲɢɛɤɢ ɜ ɬɪɚɫɫɟ ɫɬɟɤɚ ɜ ɩɪɟɞɫɬɚɜɥɟɧɢɢ JUnit, ɱɬɨɛɵ ɨɬɤɪɵɬɶ ɫɨɨɬɜɟɬɫɬɜɭɸɳɢɣ ɮɚɣɥ ɜ ɪɟɞɚɤɬɨɪɟ. 2. ɍɫɬɚɧɨɜɢɬɟ ɬɨɱɤɭ ɨɫɬɚɧɨɜɚ ɧɚ ɧɚɱɚɥɨ ɦɟɬɨɞɚ ɬɟɫɬɚ. 3. ȼɵɛɟɪɢɬɟ ɜɚɪɢɚɧɬ ɬɟɫɬɚ ɢ ɜɵɩɨɥɧɢɬɟ Debug As > JUnit Test ɢɡ ɜɵɩɚɞɚɸɳɟɝɨ Debug. Ʉɨɧɮɢɝɭɪɚɰɢɹ ɡɚɩɭɫɤɚ JUnit ɢɦɟɟɬ ɨɩɰɢɸ ɨɫɬɚɜɢɬɶ ɜ ɠɢɜɵɯ. ȿɫɥɢ ɜɚɲɚ Java VM ɩɨɞɞɟɪɠɢɜɚɟɬ ɝɨɪɹɱɭɸ ɡɚɦɟɧɭ ɤɨɞɚ ɦɨɠɧɨ ɢɫɩɪɚɜɢɬɶ ɤɨɞ ɢ 53
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɩɟɪɟɡɚɩɭɫɬɢɬɶ ɬɟɫɬ ɛɟɡ ɩɟɪɟɡɚɩɭɫɤɚ ɩɨɥɧɨɝɨ ɜɵɩɨɥɧɟɧɢɹ ɬɟɫɬɚ. ɑɬɨɛɵ ɪɚɡɪɟɲɢɬɶ ɷɬɭ ɨɩɰɢɸ, ɜɵɛɟɪɢɬɟ ɮɥɚɠɨɤ Keep JUnit running after a test run when debugging ɜ ɤɨɧɮɢɝɭɪɚɰɢɢ ɡɚɩɭɫɤɚ JUnit. 8.4. ɋɨɡɞɚɧɢɟ ɤɨɦɩɥɟɤɬɚ ɬɟɫɬɚ ȼ JUnit Ɇɚɫɬɟɪ TestSuite ɩɨɦɨɝɚɟɬ ɜɚɦ ɜ ɫɨɡɞɚɧɢɢ ɤɨɦɩɥɟɤɬɚ ɬɟɫɬɚ. Ɇɨɠɧɨ ɜɵɛɢɪɚɬɶ ɪɹɞ ɤɥɚɫɫɨɜ, ɤɨɬɨɪɵɟ ɞɨɥɠɧɵ ɫɨɫɬɚɜɥɹɬɶ ɤɨɦɩɥɟɤɬ. 1. Ɉɬɤɪɨɣɬɟ Ɇɚɫɬɟɪ New > Other. 2. ȼɵɛɟɪɢɬɟ JUnit > JUnit Test Suite ɢ ɳɟɥɤɧɢɬɟ ɧɚ Next. 3. ȼɜɟɞɢɬɟ ɢɦɹ ɤɥɚɫɫɚ ɤɨɦɩɥɟɤɬɚ ɬɟɫɬɚ (ɩɨ ɫɨɝɥɚɲɟɧɢɸ ɢɫɩɨɥɶɡɭɟɬɫɹ AllTests, ɩɨɹɜɥɹɸɳɟɟɫɹ ɩɨ ɭɦɨɥɱɚɧɢɸ).
4. ȼɵɛɟɪɢɬɟ ɤɥɚɫɫɵ, ɤɨɬɨɪɵɟ ɞɨɥɠɧɵ ɛɵɬɶ ɜɤɥɸɱɟɧɵ ɜ ɤɨɦɩɥɟɤɬ. Cɟɣɱɚɫ ɢɦɟɟɬɫɹ ɬɨɥɶɤɨ ɨɞɢɧ ɤɥɚɫɫ ɬɟɫɬɚ, ɞɪɭɝɢɟ ɦɨɠɧɨ ɞɨɛɚɜɥɹɬɶ ɜ ɤɨɦɩɥɟɤɬ ɩɨɡɠɟ. Ɇɨɠɧɨ ɞɨɛɚɜɢɬɶ ɢɥɢ ɭɞɚɥɢɬɶ ɤɥɚɫɫɵ ɬɟɫɬɚ ɢɡ ɤɨɦɩɥɟɤɬɚ ɬɟɫɬɚ ɞɜɭɦɹ ɫɩɨɫɨɛɚɦɢ: x ȼɪɭɱɧɭɸ, ɪɟɞɚɤɬɢɪɨɜɚɧɢɟɦ ɮɚɣɥɚ ɤɨɦɩɥɟɤɬɚ ɬɟɫɬɚ. x ɉɟɪɟɡɚɩɭɫɤɨɦ Ɇɚɫɬɟɪɚ ɢ ɜɵɛɨɪɨɦ ɧɨɜɨɝɨ ɧɚɛɨɪɚ ɤɥɚɫɫɨɜ ɬɟɫɬɚ. Ɇɚɫɬɟɪ ɩɨɦɟɳɚɟɬ ɞɜɚ ɦɚɪɤɟɪɚ, //$JUnit-BEGIN$ ɢ //$JUnit-END$, ɜ ɫɨɡɞɚɧɧɵɣ ɤɥɚɫɫ ɤɨɦɩɥɟɤɬɚ ɬɟɫɬɚ, ɤɨɬɨɪɵɟ ɩɨɡɜɨɥɹɸɬ Ɇɚɫɬɟɪɭ ɢɡɦɟɧɹɬɶ ɫɭɳɟɫɬɜɭɸɳɢɟ ɤɥɚɫɫɵ ɤɨɦɩɥɟɤɬɚ ɬɟɫɬɚ. Ɋɟɞɚɤɬɢɪɨɜɚɬɶ ɤɨɞ ɦɟɠɞɭ ɦɚɪɤɟɪɚɦɢ ɧɟ ɪɟɤɨɦɟɧɞɭɟɬɫɹ.
54
ɋɬɟɩɚɧɰɨɜ ȼ.Ⱥ. ɉɪɚɤɬɢɱɟɫɤɚɹ ɪɚɛɨɬɚ ɜ Eclipse 3.2
ɋɨɞɟɪɠɚɧɢɟ ȼɜɟɞɟɧɢɟ ɜ Eclipse ....................................................................................................... 3 1. ɍɫɬɚɧɨɜɤɚ ɢ ɡɚɩɭɫɤ Eclipse..................................................................................... 4 1.1. ɉɪɨɜɟɪɤɚ ɢɧɫɬɚɥɥɹɰɢɢ JRE ɢ ɩɟɪɟɦɟɧɧɵɯ CLASSPATH ............................ 7 2. ɋɨɡɞɚɧɢɟ ɩɟɪɜɨɝɨ ɩɪɨɟɤɬɚ Java.............................................................................. 9 2.1. ɉɨɥɭɱɟɧɢɟ ɤɨɞɚ ɩɪɢɦɟɪɚ (JUnit) ..................................................................... 9 2.2. ɋɨɡɞɚɧɢɟ ɩɪɨɟɤɬɚ .............................................................................................. 9 2.3. ɉɪɨɫɦɨɬɪ ɷɥɟɦɟɧɬɨɜ Java ɩɪɢ ɩɨɦɨɳɢ Package Explorer ........................... 12 3. Ɋɟɞɚɤɬɢɪɨɜɚɧɢɟ ɷɥɟɦɟɧɬɨɜ Java........................................................................... 13 3.1. Ɉɬɤɪɵɬɢɟ ɪɟɞɚɤɬɨɪɚ Java ............................................................................... 13 3.2. Ⱦɨɛɚɜɥɟɧɢɟ ɧɨɜɵɯ ɦɟɬɨɞɨɜ ........................................................................... 15 3.3. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɤɨɧɬɟɧɬɧɨɣ ɩɨɦɨɳɢ............................................................. 17 3.4. ȼɵɹɜɥɟɧɢɟ ɨɲɢɛɨɤ ɜ ɤɨɞɟ.............................................................................. 18 3.5. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɲɚɛɥɨɧɨɜ ɢɫɯɨɞɧɨɝɨ ɤɨɞɚ................................................... 20 3.6. Ɉɪɝɚɧɢɡɚɰɢɹ ɨɩɟɪɚɬɨɪɨɜ ɢɦɩɨɪɬɚ................................................................. 22 3.7. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɥɨɤɚɥɶɧɨɣ ɢɫɬɨɪɢɢ............................................................... 23 3.8. ȼɵɞɟɥɟɧɢɟ ɧɨɜɨɝɨ ɦɟɬɨɞɚ.............................................................................. 25 3.9. ɋɨɡɞɚɧɢɟ ɤɥɚɫɫɚ Java ...................................................................................... 26 3.10. ɉɟɪɟɢɦɟɧɨɜɚɧɢɟ ɷɥɟɦɟɧɬɨɜ Java................................................................. 30 3.11. ɉɟɪɟɦɟɳɟɧɢɟ ɢ ɤɨɩɢɪɨɜɚɧɢɟ ɷɥɟɦɟɧɬɨɜ Java............................................ 31 3.12. ɇɚɜɢɝɚɰɢɹ ɩɨ ɨɛɴɹɜɥɟɧɢɹɦ ɷɥɟɦɟɧɬɨɜ Java............................................... 32 3.13. ɉɪɨɫɦɨɬɪ ɢɟɪɚɪɯɢɢ ɬɢɩɨɜ............................................................................ 34 4. ɉɨɢɫɤ ɜ ɪɚɛɨɱɟɦ ɦɟɫɬɟ ......................................................................................... 37 4.1. ȼɵɩɨɥɧɟɧɢɟ ɩɨɢɫɤɚ Java ɢɡ ɪɚɛɨɱɟɝɨ ɦɟɫɬɚ ................................................ 37 4.2. ɉɨɢɫɤ ɢɡ ɩɪɟɞɫɬɚɜɥɟɧɢɹ Java......................................................................... 38 4.3. ɉɨɢɫɤ ɢɡ ɪɟɞɚɤɬɨɪɚ ......................................................................................... 39 4.4. ɉɪɨɞɨɥɠɟɧɢɟ ɩɨɢɫɤɚ ɢɡ ɩɪɟɞɫɬɚɜɥɟɧɢɹ ɩɨɢɫɤɚ .......................................... 39 4.5. ȼɵɩɨɥɧɟɧɢɟ ɩɨɢɫɤɚ ɮɚɣɥɨɜ........................................................................... 40 4.6. ɉɪɨɫɦɨɬɪ ɩɪɟɞɵɞɭɳɢɯ ɪɟɡɭɥɶɬɚɬɨɜ ɩɨɢɫɤɚ ................................................ 40 5. Ɂɚɩɭɫɤ ɩɪɨɝɪɚɦɦ.................................................................................................... 41 6. Ɉɬɥɚɞɤɚ ɩɪɨɝɪɚɦɦ ................................................................................................. 43 6.1. ȼɵɱɢɫɥɟɧɢɟ ɜɵɪɚɠɟɧɢɣ ................................................................................. 46 6.2. ȼɵɱɢɫɥɟɧɢɟ ɮɪɚɝɦɟɧɬɨɜ ................................................................................ 47 7. ɂɫɩɨɥɶɡɨɜɚɧɢɟ ɩɟɪɫɩɟɤɬɢɜɵ Java Browsing ....................................................... 48 8. ɇɚɩɢɫɚɧɢɟ ɢ ɜɵɩɨɥɧɟɧɢɟ ɬɟɫɬɨɜ JUnit................................................................ 50 8.1. ȼɵɩɨɥɧɟɧɢɟ ɬɟɫɬɨɜ ......................................................................................... 51 8.2. ɇɚɫɬɪɨɣɤɚ ɤɨɧɮɢɝɭɪɚɰɢɢ ɬɟɫɬɚ..................................................................... 53 8.3. Ɉɬɥɚɞɤɚ ɨɲɢɛɨɤ ɬɟɫɬɚ .................................................................................... 53 8.4. ɋɨɡɞɚɧɢɟ ɤɨɦɩɥɟɤɬɚ ɬɟɫɬɚ.............................................................................. 54
55
ɍɱɟɛɧɨɟ ɢɡɞɚɧɢɟ ɋɬɟɩɚɧɰɨɜ ȼɹɱɟɫɥɚɜ Ⱥɥɟɤɫɟɟɜɢɱ ɉɊȺɄɌɂɑȿɋɄȺə ɊȺȻɈɌȺ ȼ ECLIPSE 3.2 ɍɱɟɛɧɨ-ɦɟɬɨɞɢɱɟɫɤɨɟ ɩɨɫɨɛɢɟ ɞɥɹ ɜɭɡɨɜ Ɋɟɞɚɤɬɨɪ Ɍ.Ⱦ. Ȼɭɧɢɧɚ
ɉɨɞɩɢɫɚɧɨ ɜ ɩɟɱɚɬɶ 23.05.07. Ɏɨɪɦɚɬ 60×84/16. ɍɫɥ. ɩɟɱ. ɥ. 3,31. Ɍɢɪɚɠ 75 ɷɤɡ. Ɂɚɤɚɡ 973. ɂɡɞɚɬɟɥɶɫɤɨ-ɩɨɥɢɝɪɚɮɢɱɟɫɤɢɣ ɰɟɧɬɪ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ. 394000, ɝ. ȼɨɪɨɧɟɠ, ɩɥ. ɢɦ. Ʌɟɧɢɧɚ, 10. Ɍɟɥ. 208-298, 598-026 (ɮɚɤɫ) http://www.ppc.vsu.ru; e-mail:
[email protected] Ɉɬɩɟɱɚɬɚɧɨ ɜ ɬɢɩɨɝɪɚɮɢɢ ɂɡɞɚɬɟɥɶɫɤɨ-ɩɨɥɢɝɪɚɮɢɱɟɫɤɨɝɨ ɰɟɧɬɪɚ ȼɨɪɨɧɟɠɫɤɨɝɨ ɝɨɫɭɞɚɪɫɬɜɟɧɧɨɝɨ ɭɧɢɜɟɪɫɢɬɟɬɚ. 394000, ɝ. ȼɨɪɨɧɟɠ, ɭɥ. ɉɭɲɤɢɧɫɤɚɹ, 3. Ɍɟɥ. 204-133.