Informatiker Board (http://www.informatikerboard.de/board/index.php)
- Themengebiete (http://www.informatikerboard.de/board/board.php?boardid=1)
-- Praktische Informatik (http://www.informatikerboard.de/board/board.php?boardid=6)
--- Exceptiontest für JUnit (http://www.informatikerboard.de/board/thread.php?threadid=2053)


Geschrieben von Haevelin am 08.01.2015 um 18:54:

  Exceptiontest für JUnit

Hallo,

ich soll folgende Methode mit JUnit testen:


code:
1:
2:
3:
4:
5:
6:
7:
8:
public boolean zugriffErlaubt(Gehoben g, Frei f, int qualitaet) 			throws IllegaleAnfrage 
{ 		boolean ergebnis; 		
if (qualitaet > 100) 			throw new IllegaleAnfrage(); 		
if (qualitaet < 60) 			ergebnis = true; 		
else 			ergebnis = false; 		
return ergebnis; 	}




Dazu habe ich für die Werte schon geschrieben:

code:
1:
2:
3:
4:
5:
6:
7:
8:
@Test 	
public void gehobenFrei() 
{ 		
try { 			
assertEquals(k.zugriffErlaubt(gehoben, frei, 40), true); 			assertEquals(k.zugriffErlaubt(gehoben, frei, 65), false);  		 		
} catch (IllegaleAnfrage e) { 		}  	}


Wie kann ich noch auf das Werfen der Exception testen? Also wenn Qualität >100 ist??



Geschrieben von Karlito am 08.01.2015 um 20:34:

 

Schau mal hier:

http://stackoverflow.com/questions/156503/how-do-you-assert-that-a-certain-exception-is-thrown-in-junit-4-tests

Gruß,

Karlito


Forensoftware: Burning Board, entwickelt von WoltLab GmbH