Commit 90e549a7 by Patryk Czarnik

Testy JUnit

parent f77ec959
......@@ -4,4 +4,7 @@ plugins {
java {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
dependencies {
testImplementation libs.junit.junit
}
\ No newline at end of file
package alx.czysta_java.p04_funkcje;
public class Funkcje {
static void witaj(String imie) {
System.out.println("Witaj " + imie + "!");
}
static double poleProstokata(double a, double b) {
return a*b;
}
static String pozdrowienie(String imie) {
if(imie == null) {
imie = "nieznana osobo";
}
return "Witaj " + imie;
}
public static void main(String[] args) {
System.out.println("Początek programu");
// wywołanie metody statycznyj, gdy jesteśmy w tej samej klasie - jak funkcja w innych językach progr
witaj("Ala");
// wywołanie poprzez nazwę klasy, gdybyśmy byli w innym miejscu:
Funkcje.witaj("Ola");
// samo wywołaniew operacji, która posiada return nie odczytuje / wypisuje tego wyniku
poleProstokata(3, 4);
var wynik = poleProstokata(5.5, 13);
System.out.println("pole wynosi " + wynik);
System.out.println(poleProstokata(2, 3));
}
}
package alx.czysta_java.p04_funkcje;
import static org.junit.Assert.*;
import org.junit.Test;
public class FunkcjeTest {
@Test
public void poleProstokata() {
assertEquals(14.0, Funkcje.poleProstokata(3.5, 4), 0.001);
}
@Test
public void pozdrowienie() {
String wynik = Funkcje.pozdrowienie("Ala");
assertEquals("Witaj Ala", wynik);
}
@Test
public void pozdrowienieNull() {
String wynik = Funkcje.pozdrowienie(null);
assertEquals("Witaj nieznana osobo", wynik);
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@ junitVersion = "1.1.5"
espressoCore = "3.5.1"
appcompat = "1.6.1"
material = "1.10.0"
junitJunit = "4.12"
[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
......@@ -12,6 +13,7 @@ ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitV
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
junit-junit = { group = "junit", name = "junit", version.ref = "junitJunit" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment