|
Hello, I have been thrown rather into the deep end and asked to debug and create test cases for an application. I'm completely new to JUNIT, and I'll be honest my Java is not that great beyond the basics. I know the methods I want to test, and the results I want to prove. However, it's the coding that is the ... |
Hi again guys! I have unknown trouble with my code. I have a class Planta, and Im trying to make the JUnit test class for it. Planta code is: package muelles.escenario; import java.util.LinkedList; import java.util.Random; import muelles.elementos.Elemento; public class Planta { private Casilla[][] tablero; private int xLength; private int yLength; private Planta superior; private Planta inferior; public Planta(int x, int y){ ... |
One way would be to create a subclass of the BlockJUnit4ClassRunner and override the protected computeTestMethods() to return only the method(s) that you want to run, for instance the ones for which you specified a method name as a system property on the commandline (-D option). Though there must be another (simpler) way. I know the Eclipse test runner can run ... |
"Could not find the main class junit.awtui.TestRunner" On page 35 [Agile Java, Jeff Langr] Jeff specifies the command: java -cp .;C:\Programs\junit4.9\junit-4.9.jar junit.awtui.TestRunner StudentTest I am executing this from the directory where I just compiled my StudentTest class. [see p35], amending his instruction to accomodate my JUnit installation. I get an error back with 8 lines which includes the message: Could not ... |
Hello, How do I unit test (JUnit) a class that is dependent upon the class being packaged in a JAR file? I have a class to read properties from the Maven POM property file, but that file doesn't have the /META-INF/ path until it is packaged. It seems JUnit runs on the .class files. Thanks, Mike |
Hi, Im fairly new to java programming. I've been given an assignment to write a sorting algorithm and then test it using JUnit tests. The problem is when I try to compile the tester class I get a ".class expected" errors followed by three "; expected" errors for each test method I've written. Any help greatly appreciated! Here's my tester code: ... |
|
package TestZPackage; import junit.framework.TestCase; import org.junit.After; import org.junit.Before; import org.junit.Test; import ZPackage.ZClass; public class ZClassTest extends TestCase { private ZClass zclass; @Before protected void setUp() throws Exception { super.setUp(); } @After protected void tearDown() throws Exception { super.tearDown(); } public ZClassTest(String arg0) { super(arg0); zclass = new ZClass(3.0,2.0,1.0); } @Test public final void testGetPower() { assertEquals(zclass.getPower(2.0), 11.0); } } |
Hi, I have tried the source folder option. I have created one and named it Junit. I then put my Junit Suite (single file) in there (it goes in the default package) and get no errors. I then place each of the test files in the default package of the junit source file and start getting visibility errors again :s |
|
Thanks Alan Mehio, but my problem is, my class has method wich will generate one test file there is no other process takes place. And I want to write Test Class for such method ho can I do that? in this what will be my expected and actual output for the same?? |
|
George, that sounds like it might work. Just one place to change the target class, but still getting the right constructors called. MyClass1 and MyClass2 do not have a common superclass yet, but I can make one ... I presume I include only the public and protected members, and make them all abstract? |
If I understand it correctly, there are two strategies to get a list of class names (as strings) in a package; *When the project is not 'jarred', use File.dir to point to the right subdirectory and list out the .class files *When the project is 'jarred', use JarFile and openresource (or something similar) How do you write a unit test to ... |
You should read the API docs for JUnit, in particular the class org.junit.Assert. Notice, for instance, that there's a bunch of overloaded assertEquals methods that would be preferable to using the equals methods of various classes under test. Other than that, you seem to already know how to create test classes, so what's the problem? Read [this book|http://www.amazon.co.uk/Test-Driven-Development-Practical-Guide/dp/0131016490/ref=sr_1_1?ie=UTF8&s=books&qid=1208506543&sr=8-1] for a good ... |