tanszek:oktatas:unit_tesztek_alapja
This is an old revision of the document!
1. Javascript - QUnit példa Előfeltételek Editor Browser
- html5
<!DOCTYPE html> <html lang="hu"> <head> <meta charset="UTF-8"> <title>QUnit példa</title> <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-3.0.0.css"> </head> <body> <div id="qunit"></div> <div id="qunit-fixture"></div> <script src="https://code.jquery.com/qunit/qunit-3.0.0.js"></script> <script> // Tesztelendő függvény function square(x) { return x * x; } // QUnit tesztek QUnit.module("square függvény tesztelése"); QUnit.test("Pozitív szám négyzete", function(assert) { assert.equal(square(5), 25); }); QUnit.test("Negatív szám négyzete", function(assert) { assert.equal(square(-4), 16); }); QUnit.test("Nulla négyzete", function(assert) { assert.equal(square(0), 0); }); </script> </body> </html>
2. Java példa Előfeltételek
- Visual Studio Code
- JDK
java -version
- Extension pack for Java
- Maven
Lépések
- View → Command Palette: Create Java Project / Maven / maven-archetype-quickstart / version: 1.4 (legújabb), groupId: hu.example
artifactId: junit-demo
- pom.xml
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>21</maven.compiler.source> <maven.compiler.target>21</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.11.1</version> <scope>test</scope> </dependency> </dependencies>
- futtasd a maven tesztet
mvn clean test
- bal oldalt az Explorerben jobb klikk a src/main/java mappán / New File / név: Calculator.java
public class Calculator { public int add(int a, int b) { return a + b; } }
- src/test/java mappában létrehozunk hozzá egy:CalculatorTest.java
package hu.example; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; class CalculatorTest { @Test void addTwoNumbers() { Calculator calculator = new Calculator(); int result = calculator.add(2, 3); assertEquals(5, result); } }
A teljes project: teljes project
tanszek/oktatas/unit_tesztek_alapja.1790848680.txt.gz · Last modified: by superuser
