tanszek:oktatas:unit_tesztek_alapja
This is an old revision of the document!
1. Javascript - QUnit példa Előfeltételek Editor Browser
<!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 mave 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;
}
}
tanszek/oktatas/unit_tesztek_alapja.1790847984.txt.gz · Last modified: by superuser
