Junit ?????:
Junit? ?? ?? Java ?? ??? ????????.
??? junit5? ???????. junit5? Junit Platform, Junit Jupiter, Junit Vintage ? ? ?? ?? ???? ??? ???? ????. Java 8 ??? ?????. ??? ???? ???? IntelliJ IDEA???. ?? ????? ??? ?????? ???? ?? ??? ???? ???. ? ?? ??? ???? ????? ????? Junit? ?? ???? ???? ?????. ?? ?? ?? ??? ??? ????.
?? ??? ??? ??? ?? ?? ??? ??? ??, ?? ? ?????.
Junit? ????? ???? ?? ?????.
1. ??? ?? ??: ?? ?? ??? ?? ??? ??? ?????.
2. ??? ?? ??: ??? ??? ?? ??? ???? ???? ???? ???? ?? ???? ?????. ????? ??? ?? ????? ??? ???? ?? ???? ??? ?? ??? ???? ?????.
3. ??? ?? ??: ??? ???? ???? ??? ??? ????.
4. ??? ?? ??: ??? ??? ??? ?? ??? ????, ??? ??? ????, ??? ?? ?????.
???? ?? ??? ???????.
@Test: ??? ???? ?? ??? ??? ?????.
@ParameterizedTest: ???? ??? ????? ?????. ?? ? ??? ???? ?? ??? ???? ??? ???? ?? ? ??? ?? ????.
@RepeatedTest: ? ??? ???? ??? ????? ?? ?? ??? ?? ??? ? ????.
@TestFactory: ???? ??? ?? ?? ??? ??? ??? ???? ?? ?????.
@Displayname: ??? ??? ?? ??? ???? ?? ??? ?? ?? ??? ?????.
@BeforeEach: ? ??? ???? ???? ?? ??? ???? ???? ?????.
@AfterEach: ? ??? ???? ??? ?? ??? ???? ???? ?????.
@BeforeAll: ?? ???? ?? ??? ????? ?? ???? ? ????? ?? ??? ??? ??? ? ????.
@AfterAll: ?? ???? ?? ??? ??? ??? ?????.
@Disabled: ??? ??? ?? ???? ???? ??? ?????.
???:
??: ??? ???? ??????.
AssertTrue/asserFalse: ? ?? ??? ?????.
AssertNull/assertNotNull: Assert? null??? null? ????.
assertEquals/assertNotEquals: ? ?? ???? ??? ?????.
AssertArrayEquals: ?? ?? ??? ????? ?????.
AssertSame/assertNotSame: ? ??? ???? ??? ?????.
AssertThrows/assertDoesNotThrow: ??? ????? ??? ?????.
AssertAll: ?? ??? ????? ??
???? ???? ??? ?? ???? ????.
package test;//包機(jī)制 import java.lang.reflect.Array; public class MixedOperation { public int mixeOperation(int x,int y){ return division((x+y),y); } public int division(int x,int y){ int result=(x/y); return result; } public static void main(String[] args) { MixedOperation mixedOperation=new MixedOperation(); System.out.println(mixedOperation.mixeOperation(5,1)); } }
MixedOperation??? ???? ????.
package test; import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; public class MixedOperationTest { private MixedOperation mixedOperation; @BeforeEach public void init(){ mixedOperation=new MixedOperation(); } @Test public void successTest(){ System.out.println("run a test:x=4,y=2"); int result=mixedOperation.mixeOperation(4,2); Assertions.assertEquals(3,result); } /* @DisplayName("失敗") public void errorTest(){` System.out.println("run a test:x=4,y=0"); ArithmeticException exception=new ArithmeticException( ArithmeticException.class -> { mixedOperation.mixeOperation(4, 0); } ); }*/ @Disabled("參數(shù)") @Test @DisplayName("參數(shù)") @ParameterizedTest @CsvSource({"6,3,3","5,2,3","6,2,4"}) public void caTest(int x,int y,int excepted){ System.out.println("run a test :x="+x+"y="+y); System.out.println(excepted); int t= mixedOperation.mixeOperation(x,y); Assertions.assertEquals(excepted,t); } @Disabled @Test public void Next(){ System.out.println("拋出一個(gè)異常"); System.out.println(Assertions.assertThrows(IllegalArgumentException.class, () ->mixedOperation.mixeOperation(2,0))); } @Disabled @Test void error(){ Assertions.assertThrows(Exception.class,()->{Assertions.assertEquals(1,0);}); } @Test void sure(){ int result=mixedOperation.mixeOperation(4,2); Assertions.assertTrue(3==result);//斷言相等 } }
??? MixedOperationTest Class?? ???? ????. ??: "
java ??? ????? ??? ????? ??? ?????(JUnit) ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

JUnit ?? ??? ?????? ???? ???, ?? ???, ??? ?? ?? ? ???? ?? ???? ?? ?? ???? ?????. ??? ??? ??, ?? ?? ??, ???, ??? ??, ???? ?? ?? ?? ?? ?? ??? ????. Java ??????? ?? ???? ?? JUnit? ?? ??? ???? ??? ???????? ?? ? ?? ??? ???? ???.

JUnit ?????? ??? ??? ???? ???? ???? ? ?????. ?? ???? @Test(??? ??? ??), @Before(??? ???? ???? ?? ???? ???), @After(??? ??? ?? ???? ???)? ?????. ???), @BeforeClass(?? ??? ???? ???? ?? ???? ???), @AfterClass(?? ??? ???? ??? ?? ???? ???) ??? ??? ??? ??? ???? ????? ??? ??? ???? ????? ? ??? ???. ??? ??? ??? ???? ???? ?? ???? ?????.

JUnit? ?????? ?? ??? ????? ?? ??? ??? ???? Java? ?? ??? ????????. ???? ???? @Test ??? ??? ?? ??? ???? ???? ???? ?????, AssertEquals? ?? ??? ???? ???? ?? ?? ?? ?? ??? ? ????. JUnit? ?? ??, ?? ???, ?? ?? ????? ?? ?? ??? ?????.

?? ??? ???? JUnit? ??? ? ?? ??? ???? ?? ??? ????? ? ?? ???? ?? ??? ????. ?? ??? ???? ??? ??? ???? ?? ?? ????? ???? ??, ?? ??? ???? ??? ????? ???? ?? ???? ???? ??? ???? ??? ?? ??? ?????. ???? ?? ???? ConcurrentHashMap? ???? ?-? ?? ???? ?? ?? ?? ?????? ??? ??? ????? ?? ?? ???? ???? ?-? ?? ?? ???? ? ???? ???? ?? ??? ???? JUnit? ??????? ???? ???? ?????. .

JUnit ?? ??? ?????? ???? ??? ?? ??? ????? ??? ? ????. ???? ?? ???? ???? ?? ?? ?? ? ??? ?? ???? ?????. JUnit? ?? ??? ?? ?? ??? ???? ???? ?? ???? ??? ?????. ?? ???? ?? ?? ??, ?? ??, ??? ??? ??, try-with-resources ? ??? ?????. ??? ??? ??? ???? ????? ???? JUnit ??? ??? ?? ? ????.

JUnit? Spring ?????? ?? ???? Java ?? ??? ??????? ?? ??? ?? ??? ? ????. JUnit ??? ??: org.junit.jupiterjunit-jupiter5.8.1test ??? ??? ??: @ExtendWith(SpringExtension.class)? ???? ??? ??????. @Autowired ?? ?? ????, @BeforeEach ? @AfterEach? ???? ?? ? ????, @Test? ??? ???? ?????.

JUnit ?? ??? ?????? ?? ??? ??? ???? ?? ??? ?????. ???? ??? ?? ??? ??? ??? ?? ???? ???? ??? ???? ????? ?? ?? ??(???? ??) ???? ??? ?? Mocking ? Stubbing? ???? ??? ?? ?? ?? ?? ?? ??? ???? ??? ??? ????? ??

JUnit??? @RunWith ??? ???? BlockJUnit4ClassRunner ???? ???? ??? ???? ??? ???? ??? ? ????. ??? ?? ???? ??? ???? ?? ???? ?????. ?? ??? ???? ?? ??? ????? System.out.println()? ??????. JUnitAssert ??? ???? ???? ?? ?? ?? ?? ?????.
