Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

1. Application of structural testing criteria 2. Features of application of testing criteria within OOP paradigm 3. Prepare report I shared this question yesterday, but

1. Application of structural testing criteria 2. Features of application of testing criteria within OOP paradigm 3. Prepare report

I shared this question yesterday, but the same answer came as another question I shared, so I'm sharing it again, please help. Thanks and have a nice day.

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Laboratory work 3 Subject Software testing" Theme Module Testing" PART 1. Module testing in JAVA. 1.1 Objectives To acquire with the methods and techniques of module testing based on real examples of a program code done by different programming languages such as Java, C\# and C++. 1.2 Theoretical fundamentals UNIT-testing has the following characteristics: - Unit-testing is the testing on the level separate modules, functions or classes. - The goal of unit testing is to detect located in a module defects (errors). - Unit testing is "white box" testing. - Unit testing requires to create around a module special environment. It allows us to find the following types of errors: - Mistakes in algorithms; - Errors of program coding. There are different approaches to unit testing in different programming studios: - Java-Junit; - C\#-NUnit; - C++-CppUnit; - PHP - PHPUnit - JavaScript - JQuery, Qunit. 1.2.1 The sample of JUnit application JUnit library simplifies and automates the process of test preparation. To demonstrate main features of JUnit Framework, let us consider and test a primitive class written on Java This class has two methods: a) to calculate a factorial and b) to calculate a sum of two numbers: public class MathFunc \{ private int variable; public MathFunc() variable =0; \} public MathFunc(int var) \{ variable = var; \} public int getVariable() \{ return variable; \} public void setVariable(int variable) \{ this.variable = variable; \} public long factorial() \{ long result =1; if (variable >1 ) for (int i=1;i -
  • t argument for text u -
  • s argument for swing ui public static void main(String] args) \{ if (( args.length ==0)(args[0].equals("-t") )) junit.textui.TestRunner.run(AllTests.suite()); else if (args[0].equals("'-s")) junit.swingui.TestRunner.run(AllTests.class); j public static Test suite() \{ TestSuite suite = new TestSuite("Test for MathFunc"); //\$UUnit-BEGIN\$ suite.addTestSuite(TestClass); //SUUIt-ENDS return suite; y j public void testFactorialPositive() MathFunc math = new MathFunc(5); assertEquals (120, math.factorial ()) public void testPlus() MathFunc math = new MathFunc(45); assertTrue (math.plus (123)==168 ); 1.2.2 Example of performance of tests via JUnit for Eclipse At the beginning, please add junit.jar to path of your project. Installation of Eclipse has JUnit in package org.junit already. To add JUnit in your project you must: 1. Create a project "JUnitTest" 2. Open page of setup of project path (in context menu of a project) and select menu item Properties > Java Build Path). 3. Switch to tab named Libraries. 4. Add junit.jar, storing in org. junit in catalog, as external JAR for your project. To see source code of JUnit, please add junitsrc.zip to junit.jar. The archieve of source code is palced in org.eclipse.jdt. Initial source code of connection is in src/ org.junit_3.8.1. When the project JUnitTest had an access to classes JUnit, we could start to write your first test. At first, we realize the test as sub-class TestCase. You can do it or using standard Wizard Class, or special Wizard Test Case. The algorithm of your actions is: 1. Open Wizard New (File > New > JUnit Test Case). 2. Input name of class of a test "TestFailure" (see in Figure 2.1): 3. Click on Finish to create class of test. Then we add the method of testing in class TestFailure. Quick approach to create test method can be realized by pattern named test. Please, input "test" and click Ctrl+Space to activate help, then select "test". Change the name of creating method on testFailure and invoke method failo. Also please change visibility modifier to open this test method. public void testFailure( { fail (0;} To perform TestFailure, please activate tool panel and select Run as and then JUnit Test. You can inspect the testing results in view of JUnit. This view shows the state and process in a progress - Figure. 2.2. View shows in real time the current state of test performance. Representation of JUnit has two tabs: one shows you the list of errors and another - the test elements as a tree.. You can activate via found error appropriate program code using double click on corresponding item in error protocol. Understanding JUnit as quick representation, please delete operator failo in method testFailure(), and perform a test again. You can do it or by double click on button Rerun on tool panel of view, or restart a program, which was started by item of context menu named Run. Figure 2.2 - Start a test If test was with a success then you can not see the view of JUnit. But indicator of a success shows a result on icon of JUnit, but status line shows the result of a test. To remind you, that you have re-started a test, the icon view changes by adding the symbol " ". - Test with a success. - Test with a success, but the content was changed till last time. Also you can: - perform a test in a project, in a folder or in a package - Select a project, package, or initial folder and start all tuned on tests by Run as > JUnit Test. This command finds all tests inside a project, initial folder or a package. - perform single method of test - Select method of test in Outline or Package Explorer and when you click on Run as > JUnit Test, selected method is being performed. If you want to transmit the parameters or set up settings for a test, you must open dialog named Launch Configuration. Select button Run... in drop-down menu Run on tools panel - Figure 2.3. Run Create, manage, and run configurations Create a configuration that will launch a Jurit test. Figure 2.3 - Starting a test performance In this dialog you can select performing test, its arguments, and its classpath. If error occurs please act as follows: 1. Double click on error item in protocol in view of Junit to open appropriate file in editor. 2. Set up a break point at the beginning of test method. 3. Select a variant of test and click on Debug As > JUnit Test in drop-down menu named Debug. In JUnit Wizard TestSuite helps you to create a test package. You can select a series of classes as parts of a package as follows: 1. Open a Wizard - click on New 2. Select item Java > JUnit > JUnit Test Suite and click on Next. 3. Input class name of your complex of tests (as default "All Tests") - Figure. 2.4. 4. Select classes as elements of your test package. Figure 2.4 - Creation of test package You can add or delete the classes from a package in two ways: - Manually if you edit file of a package. - By re-starting a Wizard and selecting new set of test classes. Remark: Wizard adds two labels, //\$JUnit-BEGINS //SUnit-END\$, in the file of a package. They allow a wizard to change the elements of a package. We strongly don't recommend to edit the code placed between these labels. 1.3 Help infomation Hierarchy of JUnit classes: - java.lang.Object - org.junit.Assert - org.junit.Assume java.lang. Throwable (implements java.io.Serializable) java.lang.Error - java.lang.AssertionError - org.junit.ComparisonFailure - org.junit.'Test.None Annotation Type Hierarchy - org.junit. Test (implements java.lang.annotation.Annotation) - org.junit.Ignore (implements java.lang.annotation.Annotation) - org.junit.BeforeClass (implements java.lang.annotation.Annotation) - org.junit.Before (implements java.lang.annotation.Annotation) - org.junit.AfterClass (implements java.lang.annotation.Annotation) - org.junit.After (implements java.lang.annotation.Annotation) To check a correctness of performance of method in JUnit it is necessary to use group of methods Assert. They check conditions and if they are not satisfied, these methods mark a test as failed. Method Summary static assertarrayEquals (byte[] expecteds, byte[] actuals) Asserts that two byte void arrays are equal. static assertArrayEquals (char[] expecteds, char[] actuals) Asserts that two char void arrays are equal. statie assertArrayEquals [int[] expecteds, int[] actuals) Asserts that two int void arrays are equal. static assertarrayzquals(long[1 expecteds, long[] actuals) Asserts that two void long arrays are equal. static assertArrayzquals(java.lang.object[] expecteds, java.lang.object[] void actuals) Asserts that two object arrays are equal. static assertArrayEquals (short[] expecteds, short[] actuals) Asserts that two void short arrays are equal. static assertArrayEquals (java.lang.String message, byte[] expecteds, byte[] void actuals) Asserts that two byte arrays are equal. static assertArrayEquals (java.lang.String message, char[] expecteds, char[] void actuals) Asserts that two char arrays are equal. static assertArrayzquals [java.lang.string message, int[] expecteds, int[] void actuals) Asserts that two int arrays are equal. Asserts that two objects do not refer to the same object. static assertNull (java.lang.object object) Asserts that an object is null. void Function failo marks a test as failed. Please use it if you realize your own personal test and the result of this test was failed. 1.4 Task Based on previously created Java-program prepare using JUnit test classes and series of tests for each class of your Java-program. To form a series of tests please use the results reached in Laboratory work 2. Step 1. Create a project with test classes. Step 2. To be sure that all test data prepared during Laboratory work 2 were passed through with a success. ar 3. To add to test classes nethods assertTrue and/or assertFalse. Uar 4. To change Java-program by operators "try-catch" to repeat previously developed tests. 1.5 Requirements to report 1. Title. 2. Code of Java-program. 3. Code of test classes. 4. Results of testing as screen shots in Eclipse. 5. Conclusions (The defects were detected? What tests were failed? What is the best way of unit testing? A) using JUnit or B) using the mechanism of Try-Catch?). 1.6 Additional example of development of test classes Figure 2.5. Program Mathematical functions" a) b) Figure 2.6. Program Test classess
  • Step by Step Solution

    There are 3 Steps involved in it

    Step: 1

    blur-text-image

    Get Instant Access with AI-Powered Solutions

    See step-by-step solutions with expert insights and AI powered tools for academic success

    Step: 2

    blur-text-image

    Step: 3

    blur-text-image

    Ace Your Homework with AI

    Get the answers you need in no time with our AI-driven, step-by-step assistance

    Get Started

    Students also viewed these Databases questions