スキップしてメイン コンテンツに移動

投稿

ラベル(JUnit)が付いた投稿を表示しています

Automated Testing: Theory Test

Theory test is relatively new feature in JUnit testing. In theory test, we define "theory" for parameter combination and filter them by "assume". Then only tests passed parameters by assume. Let's show you some example theory test code. In Junit test, we put @RunWith(Theories.class) annotation on test class for deining theory test. put @DataPoints for parameter data set. The code below shows how theory test works in JUnit. Actually this is not good example because there is no advantedges compared with parameterized test in this case. package com.dukesoftware.exchangerate.service; import junit.framework.Assert; import org.junit.After; import org.junit.BeforeClass; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; import org.mockito.Mockito; import com.dukesoftware.exchangerate.api.ExchangeRateApi; import com.dukesoftware.

Automated Testing: Unit Test by JUnit

Unit testing From this post, I will explain basic of automated testing. In this post, I will show you very very basic of unit testing using JUnit. We use YahooExchangeRateApi as testing target code introduced in http://dukesoftware00.blogspot.com/2013/10/java-get-exchange-rate-from-yahoo.html . Unit Test class & Annotaions The first of first, write simple unit testing code for YahooExchangeRateApi class. A few things you should remenber: Add @Test annotation to test method. Use @BeforeClass for execute something *once* before actual all tests defined in the test class. Use @Before for execute something before actual *each* tests defined in the test class. Use @AfterClass and @After are simply opposite meaning of @BeforeClass and @Before. e.g. executed after test methods. You can test exception thrown by @Test(expected=Exception.class) Yeah that's all! Let's see the actual test class code.... package com.dukesoftware.exchangerate.api; import static junit.fra