I recently read (link text) about a way to statically add tests to test suite in JUnit 4? What about a dynamic way, i.e. how to add a test class if its name is known not earlier than at run-time, e.g. its name is read from XML file?
I know how to do it. I can use JUnitExt library (http://junitext.sourceforge.net). It supports "declarative test configurations (as provided by TestNG)". See junitext.sourceforge.net/tutorial.html (How to parameterize tests using XML).
I don't know of a way to add to an existing suite, but you can create your own suite at runtime. The JUnitCore class lets you pass in a list of classes you want run. These can be read in from anywhere you like including XML.
Related
I have some classes for which I dont have to write junit classes so I want to skip Junit for some Java classes and want to increase Junit code coverage using Maven. For example, I have placed all Java classes in com.test.xxx package so that I can tell them all classes are to be skipped.
You can use a #Disabled Tag to disable a specific Test. If you just have empty test classes, for whatever reason. Delete them.
If you want to fake code coverage for whatever reason, you can create tests and call your services inside the tests, but do not add any assertations... However this is extremly bad practice and I cant really suggest it to you.
I want to improve the Builder Pattern Eclipse Plugin. I want to change the code generated to support generics class and include the class name in the builder class name.
I located where I must add my changes. I want to use TDD but I'm stuck as I don't know how to create an ICompilationUnit type. I want to create an ICompilationUnitfrom test file and then compare the result to what I expect. I know I can mock it but I don't know well the interface and what each method should do.
I didn't find resources to solve my problem. The resources I found are about GUI testing.
Sadly, the ICompilationUnit defined by JDT is not a simple class, so if you want to unit test it, either you have to mock it (and thus understand what is expected), or you have to use JDT to parse it. For basics, you can use the vogella.com JDT tutorial.
Furthermore, I would look into the test suite of JDT itself, as there were similar issues solved already.
I'm new to unit testing.
I have a existing maven based project, now my management has asked me to create unit test for all the classes.
So is there any way to automatically generate test classes based on my src package structure.
What I mean is rather than manually replicating the package structure is it possible to automatically generate Test classes.
For instance, if I have com.company.HelloWorld in src folder can it automatically generate com.company.HelloWorldTest in test folder.
Note: actually I do not want the code to be generated automatically just wanted the package structure and test classes to be created within which I can write my own code.
I do not know a way to create unit tests automatically. Actually it is almost impossible. Unit test is a class, i.e. code that is typically written by human.
You want to create templates for unit tests. But if you do this automatically they will be empty and there is no way then to prevent you from running empty test cases and be happy that all tests succeed.
So, taking in consideration that you have a tiny project (45 classes) I'd recommend you to create your tests manually. You can however use Eclipse plugin that helps you to create empty test case in correct package.
We have existing Java tests that singularly tests our back end. These tests are pretty elaborate, and also run as a single users. I would like to know if I can simply take these existing tests/classes/libraries/jars etc and just wrap JMeter around them to execute them as JMeter tests from the command line (i.e. Maven).
Maybe add in some listeners and other JMeter components, but the tests are perfect the way they are except that they are not multi-threaded and do not have the reporting functions that JMeter has.
Can this be done using JSR233?
What if my libraries are located elsewhere? How can I use them in the JMeter project?
You have at least 3 options:
Implement JavaSamplerClient by extending AbstractJavaSamplerClient, this class will call your class. Create a Jar from this and put it in jmeter/lib/ext + add dependencies to jmeter/lib folder and you can then use Java Request and select your class.
Use JSR223 Sampler + Groovy wrapper for your class
Use JUnit Sampler if you have some JUnit classes
I'm looking for some kind of test (mostly jUnit, but not exclusivelly) management. What I have in mind is a tool that would allow to easily enable/disable individual tests based on configuration (xml file, property file or in DB etc.).
I was thinking that there must be some maven plugin that could do that, or some tool. Can you suggest anything?
There are Maven plugins for JUnit and TestNG that allow you to define which tests to run from the command line (or all).
JUnit allows the creation of test suites. With some care, you can tailor your test suites to match your "to be enabled / disabled" sets of tests.
Failing that, you could wrap the test suite idea with something that generates / references an XML file for configuration (if that's really the path you want to take). Considering that it's all in a Java class, you might find it easier to do by another means (perhaps an properties file or just in-class handling).