Skip to content

Commit

Permalink
testing Parameterized tests in JUnit4
Browse files Browse the repository at this point in the history
  • Loading branch information
giriharan13 committed Sep 24, 2023
1 parent 1237fab commit 342cd21
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
2 changes: 1 addition & 1 deletion junit-4-basics/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
Expand Down
13 changes: 10 additions & 3 deletions junit-4-basics/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.compiler.source=1.8
17 changes: 17 additions & 0 deletions junit-4-basics/src/main/java/com/giriharan/StringUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.giriharan;

import java.util.stream.IntStream;

public class StringUtils {

String addString(String s1,String s2)
{
return s1+s2;
}

int countVowels(String s)
{
return (int) s.chars().filter(arg -> arg=='a' || arg=='e' || arg=='i' || arg=='o' || arg=='u').count();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.giriharan;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class StringUtilsParamTest {

StringUtils su;
String s1,s2,expected;

@Before
public void init()
{
su = new StringUtils();
}

public StringUtilsParamTest(String s1,String s2,String res)
{
this.s1 = s1;
this.s2 = s2;
this.expected = res;
}


@Parameters
public static Object[] testAddValues() {
return new Object[] {
new Object[] {"Hello","World","HelloWorld"},
new Object[] {"","world" ,"world"},
new Object[] {"hello","","hello"}
};
}

@Test
public void testAdd() {
assertEquals(expected,su.addString(s1, s2));
}

}

0 comments on commit 342cd21

Please sign in to comment.