Unit test with JUnit

Hi all,
I use Eclipse IDE: Eclipse Java EE IDE for Web Developers. Version: Indigo Release
I use JUnit 4. For project properties> Java Build Path> Libraries: I have JUnit4 added. Also under the same tab: Maven Dependencies> I have junit-4.8.2.jar
In pom.xml I have:
<dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.2</version>
      <scope>test</scope>
    </dependency>Basically, I’m writing unit tests using JUnit in the past few months! All I needed to do was to create a test class, add a test method like below:
@Test
public void testMethod(){
          // Some test code
}Right click on method, Run As> JUnit Test
That’s all I needed to do to either run my unit test or do Debug As> Junit Test to debug my unit test.
All was fine with the world! Starting yesterday, when I add a new test method in a test class, and then do: Right click on method, Run As> JUnit Test
Nothing happens! I cannot run or debug any test anymore! Meaning I cannot add any new unit test!
Let me also add that after I add my test method, I do a clean build thru Eclipse and Eclipse sees the newly complied class which contains my new test method.
Since none of my configurations changed, I have no idea what went wrong!
Does anybody has any idea? Any help would be greatly appreciated.

aksarben wrote:
Yes, I have an idea: Post your code. I for one am not going to my waste my time speculating and guessing.Could also just be IDE crud. I've had similar problems with older versions of Eclipse. Never with current ones though.
OP: eclipse creates run/debug configurations for each class. If you search around a little you should find the dialog, I don't know the exact name. I think you can reach it from the "run as" menu options. You should try clearing the settings of your test suite to see if that changes anything.

Similar Messages

  • Unit tests with ant (FB4 beta)?

    Since flexunit is integrated with FB4, I was wondering how to run unit tests with ant on FB4 (using 3.4 sdk). In my current ant build file, the <mxmlc> and <compc> tags both work but the tag <flexunit> does not seem to work anymore (it worked on FB3 with flexunit download). So is there anyway currently to run unit tests on FB4 using ant?

    Hi,
    Let us take your requirements as separate two requriements.
    1. Using the flexunit ant task - I think for this you needed a separate ant library to support this. So this may be missing in the ant available with FB. May be you can analyse this and add on your own and try out.
    2. Debuggin the results.
    Now FlexBuilder has the feature inbuilt as part of the IDE which provides more featuers like , source naviagation, rerunnig , saving results loading results etc.FlexBuilder uses its own set up to show the results details in IDE.
    Currently other than using the feature in FB, there is no way to debug the results of the tests. However if you would like to get the tests to be run by ant task, and analyse the results, the following can be used.
    Option 1 : Run outside FB, show and analyse results in FB
    a. Use the FB, create some sample testCases in FB.
    b. Use 'Execute FlexUnit tests' from the run,  or debug launcher
    c. Use the option Save configuration. This will get the configuration as xml or mxml file. You can use this file template and generate your test cases (may be you will configure your tests in a testSuite class and always use that as the input to the application, so that application syntax never changes). If you run the mxml created swf  (whch you can do by the simple ant tasks which does not use the flexunit task ) out side FlexBuilder and if the FlexBuilder is open, you can still see the results in the FB and analyse the results. (You need the library which is used by the FB to use the classes. You can get the location of swc file by inspecting the library path of a project in which you have added the testCase or testSuite class using the FB IDE)
    Option2:Run outside FB and  Analyse the results in FB.
    If you have the project for which you have run the tests, and you have the XML results of the run, you can still analyse the results in the FlexBuilder.
    a. Ensure that the report is in the required syntax of FB. (we have tried to use the similar syntax as that of the JUnit resutl report)
    b. Use FB, load your project, open the FlexUnit result view, use the open result option in the FB. This should load the XML in FB (we have only ensured to open the result files which were created using FB ,back in the result view. So if you are facing some issue in opening your XML, you can refer the required syntax by saving a sample run result from FB)
    Option 3: Run and analyse the results in FB.
    a. Have the input setup mentioned to FB. (If you would like to integrate changes, have a suite class which will take care of this and mention in the Execute FlexUnit tests to use this suite class. But there is no way to specify to run the FB commands outside FB.)
    b. So whenever you would like to anlyse the tests, you need to run your test in FB and then analyse the results shown in result view.
    Please let me know whether this is what you are looking for.
    Thanks,
    Rani

  • Unit Testing with Microsoft Sharepoint Emulators and Fakes with Visual Studio 2013

    Hi All,
    I have created Test Project and now creating Test cases for Sharepoint. I found a link on MSDN which suggests using Fakes framework but it supports VS2012 and I am using Visual Studio 2013.
    So how can I use it with VS2013 or is there any other way with which I can implement the Test cases with VS2013.
    Please suggest.
    Thanks in advance.
    Himanshu Nigam

    Hi HimanshuNigam,
    According to your descrition, my understanding is that you want to use Fakes framework to create test case for SharePoint project in Visual Studio 2013.
    If you want to test using Fakes Framework, you can use the codeplex extension to achieve it. It supports Visual Studio 2013.
    Here is a detailed article for your reference:
    Better Unit Testing with Microsoft Fakes
    About how to include the Nuget package, you can use the package with the link below:
    NuGet Package Manager for Visual Studio 2013
    Installing NuGet
    If you still have question about this issue, I suggest you can create a post in Visual Studio, more experts will help you and you can get more detailed information from there:
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=visualstudio%2Cvsarch%2Cvsdbg%2Cvstest%2Cvstfs%2Cvsdata%2Cvsappdev%2Cvisualbasic%2Cvisualcsharp%2Cvisualc
    Best Regards
    Zhengyu Guo
    TechNet Community Support

  • Unit Tests with Jemmy

    I currently write some Unit Tests with jemmy. But i did not find a solution to run it headless. The test should run on a hudson build server and there is no X installed. Are there any solutions?
    cheers
    Andy

    Not presently, we have the same issue internally. I have a half-finished "Headless Glass" implementation would allow exactly this, but due to other (crucial and exciting) FX work I am doing at the moment, I haven't been able to finish this.

  • [svn:osmf:] 11159: Updating unit test with a check to all expected events firing properly.

    Revision: 11159
    Author:   [email protected]
    Date:     2009-10-26 12:12:10 -0700 (Mon, 26 Oct 2009)
    Log Message:
    Updating unit test with a check to all expected events firing properly.
    Modified Paths:
        osmf/trunk/framework/MediaFrameworkIntegrationTest/org/osmf/content/TestContentElementInt egration.as

    camickr wrote:
    Do you really expect us to read all that code to try and understand what you are attempting to do?
    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
    http://homepage1.nifty.com/algafield/sscce.html
    Absolutely not, I wouldn't post such a large amount of code expecting people to read it. I indicated that I believe my error only lies within one of two classes, and that I highlighted the two methods with comments.
    I was told to create an SSCCE as you have mentioned, but I believe all of this code is necessary for the program to run properly, so I only provided it all for compilation purposes.
    I'll check the examples posted, and if I need to I'll see if I can change my methods to use the swing timer class as the first reply mentions, but I did not think this would be necessary.
    Edited by: Drew___ on Nov 29, 2007 3:28 AM
    I have just figured out what my problem was, sorry it was quite a simple mistake. When checking for user input, I was immediately resetting the eventFlag or something afterwards. This meant the object would stop moving as it couldn't remember my last keypress. Thanks for your help, those tutorials are really good.

  • Unit testing with TLF

    While unit testing complex formating, I hit several problems. Below are simple tests that fail with an error. Does anybody know what is wrong with these tests?
    Thanks for any hints,
    Marc
        public function test_apply_Link():void
            var init:XML = <TextFlow xmlns="http://ns.adobe.com/textLayout/2008"><p><span>aaa</span></p></TextFlow>
            var textFlow:TextFlow = TextConverter.importToFlow(init, TextConverter.TEXT_LAYOUT_FORMAT)
            var editManager:IEditManager = new EditManager()
            textFlow.interactionManager = editManager
            editManager.selectRange(1,2)
            editManager.applyLink("http://livedocs.adobe.com/", "_self", true) // throws error:
            RangeError: Error #2006: The supplied index is out of bounds.
                at flash.text.engine::GroupElement/replaceElements()
                at flashx.textLayout.elements::ParagraphElement/http://ns.adobe.com/textLayout/internal/2008::insertBlockElement()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_core\src\flashx\textLayout\elements\ParagraphElement.as:277]
                at flashx.textLayout.elements::FlowLeafElement/http://ns.adobe.com/textLayout/internal/2008::createContentElement()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_core\src\flashx\textLayout\elements\FlowLeafElement.as:95]
                at flashx.textLayout.elements::SpanElement/http://ns.adobe.com/textLayout/internal/2008::createContentElement()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_core\src\flashx\textLayout\elements\SpanElement.as:77]
                at flashx.textLayout.elements::ParagraphElement/http://ns.adobe.com/textLayout/internal/2008::createTextBlock()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_core\src\flashx\textLayout\elements\ParagraphElement.as:100]
                at flashx.textLayout.elements::ParagraphElement/http://ns.adobe.com/textLayout/internal/2008::createContentElement()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_core\src\flashx\textLayout\elements\ParagraphElement.as:241]
                at flashx.textLayout.elements::SubParagraphGroupElement/http://ns.adobe.com/textLayout/internal/2008::setParentAndRelativeStart()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_core\src\flashx\textLayout\elements\SubParagraphGroupElement.as:178]
                at flashx.textLayout.elements::LinkElement/http://ns.adobe.com/textLayout/internal/2008::setParentAndRelativeStart()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_core\src\flashx\textLayout\elements\LinkElement.as:495]
                at flashx.textLayout.elements::FlowGroupElement/replaceChildren()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_core\src\flashx\textLayout\elements\FlowGroupElement.as:764]
                at Function/http://adobe.com/AS3/2006/builtin::apply()
                at flashx.textLayout.elements::ParagraphElement/replaceChildren()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_core\src\flashx\textLayout\elements\ParagraphElement.as:302]
                at flashx.textLayout.edit::TextFlowEdit$/insertNewSPBlock()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_edit\src\flashx\textLayout\edit\TextFlowEdit.as:655]
                at flashx.textLayout.edit::TextFlowEdit$/makeLink()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_edit\src\flashx\textLayout\edit\TextFlowEdit.as:503]
                at flashx.textLayout.operations::ApplyLinkOperation/doOperation()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_edit\src\flashx\textLayout\operations\ApplyLinkOperation.as:146]
                at flashx.textLayout.edit::EditManager/doInternal()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_edit\src\flashx\textLayout\edit\EditManager.as:418]
                at flashx.textLayout.edit::EditManager/doOperation()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_edit\src\flashx\textLayout\edit\EditManager.as:321]
                at flashx.textLayout.edit::EditManager/applyLink()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_edit\src\flashx\textLayout\edit\EditManager.as:1137]
        public function test_undo():void
            var init:XML = <TextFlow xmlns="http://ns.adobe.com/textLayout/2008"><p><span>aaa</span></p></TextFlow>
            var textFlow:TextFlow = TextConverter.importToFlow(init, TextConverter.TEXT_LAYOUT_FORMAT)
            var undoManager:IUndoManager = new UndoManager()
            var editManager:IEditManager = new EditManager(undoManager)
            textFlow.interactionManager = editManager
            editManager.selectRange(1,2)
             var format:TextLayoutFormat = new TextLayoutFormat()
            format.fontWeight = FontWeight.BOLD
            editManager.applyLeafFormat(format)
            undoManager.undo() // throws error:
            TypeError: Error #1009: Cannot access a property or method of a null object reference
                at flashx.textLayout.edit::EditManager/performUndo()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_edit\src\flashx\textLayout\edit\EditManager.as:540]
                at flashx.textLayout.operations::FlowOperation/performUndo()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_edit\src\flashx\textLayout\operations\FlowOperation.as:181]
                at flashx.undo::UndoManager/undo()[E:\dev\trunk\frameworks\projects\textLayout\textLayout_edit\src\flashx\undo\UndoManager.as:197]            

    For your second issue, you didn't display TextFlow before you selected the Text.  I also changed the FontWeight.BOLD to "bold" in order to pass compilation.  The code below should work:
    var  
    var controllerOne:ContainerController = new ContainerController(container, 500, 500); 
    var undoManager:IUndoManager = new UndoManager() 
    var init:XML = <TextFlow xmlns="http://ns.adobe.com/textLayout/2008"><p><span>aaa</span></p></TextFlow>  
    var textFlow:TextFlow = TextConverter.importToFlow(init, TextConverter.TEXT_LAYOUT_FORMAT) 
    addChild(container);
    textFlow.flowComposer.addController(controllerOne);
    textFlow.flowComposer.updateAllControllers();
    var editManager:IEditManager = new EditManager();textFlow.interactionManager = editManager;
    editManager.selectRange(1,2)
    var format:TextLayoutFormat = new TextLayoutFormat();format.fontWeight ="bold";container:Sprite = new Sprite(); 
    editManager.applyLeafFormat(format);
    undoManager.undo();
    textFlow.flowComposer.updateAllControllers();

  • Unit test with Dynamic Value Query

    Hi,
    I am planing a function which should return a table name for a given ROWID. The ROWID will be selected from a view. Now I am trying to setup a unit test which consists of Startup and Teardown Process as well as a Dynamic Value Query. During Startup Process one dataset is inserted in a table which is part of a view definition. The dataset should be selected during Dynamic Value Query. However I am getting the following error message: Unable to run the test because no rows were returned by the dynamic query. Is there the possibility that within a Dynamic Value Query I can't make use of datasets which where inserted by a Startup Process? I am asking because the selection outside the unit testing framework supplies the dataset as expected.
    SQL Developer: 3.2.20.09 Build MAIN-09.87
    Java: 1.6.0_45
    Regards.

    Dynamic SQL is very tricky.  Since you can get the data outside your application extract and test the dynamic SQL as it is generated.  When working with dynamic SQL I find it useful to first generate the SQL text as a string and then if necessary store it in a table (CLOB type) for later reference.  Because of the uncertainty of obtaining bind variable values later I prefer to hard-code such values into dynamic SQL - possibly slightly less efficient for Oracle at run time but a lot easier to work with when debugging and tuning (again, apart from the built-in inefficiency of not using bind variables)  I usually find the overhead of the hard-coded values not too bad and the ability to know the data values at a glance useful.  I also find it useful to write dynamic SQL in such a way so that the resulting statement can be pasted in to any normal SQL tool (SQL*PLUS, SQL*Developer) and run without any editing.
    There may be some quirk in the generated dynamic SQL preventing it from finding anything.
    Good luck.

  • Xtext Unit tests with JUnitParam

    Hey,
    I do some testing with Xtext. Somehow I ended up with a lot of boilerplate code and would like to get rid of it by using JUnitParam. Both Xtext and JUnitParam require the use of @RunWith annotation.
    @RunWith(JUnitParamsRunner.class)
    @RunWith(XtextRunner)
    class MyDslValidationTest {
    // test code ...
    This will not work ... How do I get both to work ?
    Thank you.
    Kon

    Thank you Christian Just in case if someone else is having the same issue:
    import com.google.inject.Inject
    import junitparams.JUnitParamsRunner
    import junitparams.Parameters
    import org.eclipse.xtext.formatting.INodeModelFormatter
    import org.eclipse.xtext.formatting.impl.DefaultNodeModelFormatter
    import org.eclipse.xtext.junit4.util.ParseHelper
    import org.eclipse.xtext.resource.XtextResource
    import org.eclipse.xtext.util.Pair
    import org.eclipse.xtext.util.Tuples
    import org.junit.Before
    import org.junit.Test
    import org.junit.runner.RunWith
    import static extension org.assertj.core.api.Assertions.*
    @RunWith(JUnitParamsRunner)
    class TestFormatterTest {
    @Inject extension ParseHelper<Model> parseHelper = new ParseHelper
    @Inject extension INodeModelFormatter nodeModelFormatter = new DefaultNodeModelFormatter
    @Before
    def void before() {
    var i = new TestStandaloneSetup().createInjectorAndDoEMFRegistration
    i.injectMembers(parseHelper)
    i.injectMembers(nodeModelFormatter)
    @Test
    @Parameters
    def void testFormat(Pair<CharSequence, CharSequence> pair) {
    pair.first.assertFormattedAs(pair.second)
    def static parametersForTestFormat() {
    Tuples.create('''test { bla }''',
    '''test {
    bla
    def void assertFormattedAs(CharSequence input, CharSequence expected) {
    (input.parse.eResource as XtextResource).parseResult.rootNode.format(0, input.length).formattedText.assertThat.
    isEqualTo(expected)

  • UIX Unit Test with HttpUnit

    Hi
    I would like to test my UIX pages with HttpUnit. I am always having an exception while trying to get a page. Here is my code:
    package mypackage;
    import com.meterware.httpunit.TableCell;
    import com.meterware.httpunit.WebTable;
    import junit.framework.TestCase;
    import com.meterware.httpunit.GetMethodWebRequest;
    import com.meterware.httpunit.WebConversation;
    import com.meterware.httpunit.WebRequest;
    import com.meterware.httpunit.WebResponse;
    public class TestThree extends TestCase
    public TestThree(String name)
    super(name);
    public void testTable() throws Exception
    WebConversation webConversation = new WebConversation();
    WebRequest request = new GetMethodWebRequest("http://localhost:8988/HttpUnitTest-View-context-root/table.do");
    WebResponse response = webConversation.getResponse(request);
    Here is the exception thrown:
    ReferenceError: "event" is not defined.
         at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597)
         at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:557)
         at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1076)
         at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2265)
         at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:58)
         at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.performEvent(JavaScript.java:172)
         at com.meterware.httpunit.scripting.ScriptableDelegate.doEvent(ScriptableDelegate.java:56)
         at com.meterware.httpunit.WebResponse$Scriptable.load(WebResponse.java:689)
         at com.meterware.httpunit.javascript.JavaScript.load(JavaScript.java:89)
         at com.meterware.httpunit.javascript.JavaScriptEngineFactory.load(JavaScriptEngineFactory.java:58)
         at com.meterware.httpunit.RequestContext.runScripts(RequestContext.java:44)
         at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:122)
         at com.meterware.httpunit.WebClient.getResponse(WebClient.java:113)
         at mypackage.TestThree.testSailorsTable(TestThree.java:19)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at junit.framework.TestCase.runTest(TestCase.java:154)
         at junit.framework.TestCase.runBare(TestCase.java:127)
         at junit.framework.TestResult$1.protect(TestResult.java:106)
         at junit.framework.TestResult.runProtected(TestResult.java:124)
         at junit.framework.TestResult.run(TestResult.java:109)
         at junit.framework.TestCase.run(TestCase.java:118)
         at junit.framework.TestSuite.runTest(TestSuite.java:208)
         at junit.framework.TestSuite.run(TestSuite.java:203)
         at junit.framework.TestSuite.runTest(TestSuite.java:208)
         at junit.framework.TestSuite.run(TestSuite.java:203)
         at junit.swingui.TestRunner$16.run(TestRunner.java:623)
    Any help would be welcomed.

    My question is more precisely if Sql Developer takes into account an argument like type Table Of Record, or an argument like type ...%ROWTYPE (knowing there is no problems with an argument like type Record)
    Thank you for your answers.

  • Re: Unit Tests with Jemmy

    I have a need for running headless beyond just for testing. I'd like to make a library that uses JavaFX properties/tasks that can either run headless, or can use the same tasks to run in a GUI that can display the progress info generated by the tasks. javafx.concurrent.Task seems perfect, except that when I try to run a task inside a maven mojo, I get:
    java.lang.IllegalStateException: Toolkit not initialized
    I'm currently running JavaFX 2.2.7 on OS X 10.8.3.
    Is there a way to enable properties/Task in a headless environment on 2.2.7? Will there be a way for 8.0?
    I don't need to run any GUI stuff headless, I just want to use the excellent JavaFX properties model in a way that is reusable across GUI and headless environments.
    Thanks,
    Keith

    I would create a feature request here if it https://javafx-jira.kenai.com/secure/Dashboard.jspa if it doesnt' exist. You can download the Java 8 builds here http://jdk8.java.net/
    Also your error for some other unknown reasons, though I'm, not too sure...
    Btw since you replied to my other topic, what's a headless :P?

  • ABAP unit: test classes part of prod. code

    Hi all,
    I've read <a href="https://weblogs.sdn.sap.com/pub/u/266">Thomas Weiss</a>'s weblog: <a href="/people/thomas.weiss/blog/2004/12/17/a-spotlight-on-abap-unit-part-1 Spotlight on ABAP Unit Part 1</a>.
    I posted a question there, but apparently Thomas can't answer at the moment, and since I'm impatient for getting someone's opinion, I reckon we can discuss that topic here  :^)
    As explained in the <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/c1be1003-0701-0010-3795-f87160de6483">NetWeaver Developer’s Guide Using ABAP</a>, the test classes are part of the program under test (PUT):
    <i>In ABAP Unit, test classes are part of the production code of the TU. This avoids problems arising from the test code being separate from the production code:
    - Programs and tests must be kept synchronized.
    - You have to ensure that the test and program code are transported together.
    - External test code only enables black box tests with an outside perspective of the tested program.
    Since the test code is part of the production code, it is easy to keep the unit tests and the
    production code up to date if the latter is changed.
    Although the test code and the production code are transported through the system landscape, ABAP unit tests do not increase the load on the production system. By default, the test code is not compiled in the production system. Therefore, the test code can never be executed in the production system.</i>
    On the other hand, this idea is quite different from what suggested by other unit testing frameworks.
    For instance, the documentation of <a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html">Test::Unit - Ruby Unit Testing Framework</a> reads:
    <i>It‘s handy to collect a bunch of related tests, each test represented by a method, into a common test class that knows how to run them.
    The tests will be in a separate class from the code they‘re testing for a couple of reasons. First of all, it allows your code to stay uncluttered with test code, making it easier to maintain. Second, it allows the tests to be stripped out for deployment, since they‘re really there for you, the developer, and your users don‘t need them. Third, and most importantly, it allows you to set up a common test fixture for your tests to run against.</i>
    Regarding the advantages outlined by NetWeaver Developer’s Guide:
    - Programs and tests might be kept synchronized even if they don't belong to the same unit of code.
    - Moreover, you could assure that the test and program code are transported together by saving them in the same package.
    - And quite frankly, I don't have a thourough understanding of the reason why external tests only allow <i>black box tests with an outside perspective</i>.
    What are your opinions on this?
    Regards, Davide

    Hi,
    when I started unit testing with JUnit I was quite surprised that SAP groups the tests with the production code. But now I actually really like it. It has a few advantages:
    - Good tests serve as an excellent documentation so why not bundling them together.
    - If you want to look at the tests they are easy to find.
    - I write all my class tests as local classes. I found out that it really helps me to focus on writing tests only for the class under test. Sometimes it is quite easy to forget the "unit" and write integration tests again.
    Regarding your question:
    >And quite frankly, I don't have a thourough understanding of the reason why external tests only allow black box tests with an outside perspective.
    Usually I would not use the term black box testing in this context. Maybe you mean that it is easy to access private attributes, methods when you group class and testclass together?
    Normally black box testing means that you cannot look at the implementation of the code under test. So your tests are based on the specifications or if there is not one, on your common sense.
    cheers
    Thomas

  • Deployed models are cached during unit tests

    I am using Stardust 2.1.1, and currently I am writing unit tests with JUnit, Spring and an in-memory Derby database. I would like to create a clean state for each of the unit tests, so I create and initialize the database before every test method and drop it after method executions. I also dispose of the Spring application context and initialize it between test methods with the @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) annotation.
    My problem is that despite dropping the database and reinitializing the Spring context after every test method my previously deployed models are still cached and I get an authorization-related exception:
    org.eclipse.stardust.common.error.AccessForbiddenException: AUTHx01000 - The user 'motu' does not have the permission 'model.deployProcessModel'.
    at org.eclipse.stardust.engine.core.runtime.utils.Authorization2.checkPermission(Authorization2.java:332) ~[carnot-engine-2.1.1.jar:2.1.1]
    at org.eclipse.stardust.engine.core.runtime.beans.interceptors.GuardingInterceptor.invoke(GuardingInterceptor.java:52) ~[carnot-engine-2.1.1.jar:2.1.1]
    at org.eclipse.stardust.engine.core.runtime.interceptor.MethodInvocationImpl.proceed(MethodInvocationImpl.java:130) [carnot-engine-2.1.1.jar:2.1.1]
    at org.eclipse.stardust.engine.core.runtime.beans.interceptors.AbstractLoginInterceptor.performCall(AbstractLoginInterceptor.java:201) ~[carnot-engine-2.1.1.jar:2.1.1]
    at org.eclipse.stardust.engine.core.runtime.beans.interceptors.AbstractLoginInterceptor.invoke(AbstractLoginInterceptor.java:131) ~[carnot-engine-2.1.1.jar:2.1.1]
    at org.eclipse.stardust.engine.api.spring.SpringBeanLoginInterceptor.invoke(SpringBeanLoginInterceptor.java:79) ~[carnot-spring-2.1.1.jar:2.1.1]
    at org.eclipse.stardust.engine.core.runtime.interceptor.MethodInvocationImpl.proceed(MethodInvocationImpl.java:130) [carnot-engine-2.1.1.jar:2.1.1]
    at org.eclipse.stardust.engine.api.spring.SpringSessionInterceptor.doWithDataSource(SpringSessionInterceptor.java:142) ~[carnot-spring-2.1.1.jar:2.1.1]
    at org.eclipse.stardust.engine.api.spring.SpringSessionInterceptor.access$000(SpringSessionInterceptor.java:48) ~[carnot-spring-2.1.1.jar:2.1.1]
    at org.eclipse.stardust.engine.api.spring.SpringSessionInterceptor$1.doInConnection(SpringSessionInterceptor.java:87) ~[carnot-spring-2.1.1.jar:2.1.1]
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:350) ~[spring-jdbc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    I looked into the code and found out that the ModelManagerBean and ModelMananagerBeanPartition classes cache my test model. I set the Infinity.Engine.Caching property to false in my carnot.properties as per the online documentation but the model is still getting cached.
    What is the proper way to disable caching in Stardust or how can I ensure that it disposes of everything that is cached?
    Thank you.

    In the Authorization2.checkPermission(...) method there's the following call:
    List<IModel> models = ModelManagerFactory.getCurrent().findActiveModels();
    This is a call to the ModelManagerPartition.findActiveModels() method. This class also has a deleleAllModels() method. If I try to call either of them manually after deploying the model in the first test, I get a NullPointerException.

  • Unit Testing of servlets and jsp by Junit

    hi,
    suggest me how to do the unit testing by junit!
    thanks in advance

    Or abstract the business logic away from the actual servlets themselves (always a good idea) and test those classes outside the context of a servlet framework.
    That limits the code that actually is impacted by being a servlet to the absolute minimum (essentially parameter passing).

  • BeginTimer and EndTimer Not Working In Data-Driven Unit Test Using DataSource Attribute

    Using VS2012 Ultimate I have a unit test with the <DataSource> attribute which passes in values from a CSV file.  I'm wrapping the unit test in a load test.  I expect a Transaction to appear in the load test results for each row in my DataSource
    due to the BeginTimer and EndTimer methods in the unit test.  However, I only get 1 transaction, with response time roughly equal to the overall test time.  For example, if each row in the DataSource takes 1 second to process, then my test time and
    transaction time would be about 10 seconds with 10 rows in the CSV file.
    I've created a load test with Constant Load Pattern, 1 user, and 1 test iteration.  Seeing the behavior described above.
    I have tried with and without and the check for $LoadTestUserContext.  I'm only using that because I get a NotSupportedException when running the unit test on its own.  I can't believe this bug still
    exists, but that is another topic.
    Note also that I cannot see the Debug output in the Output window in VS2012.
    Any tips?  Thank you.
        <TestMethod()>
        <DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\TestData\MyValues.csv", "MyValues#csv", DataAccessMethod.Sequential)>
        Public Sub WebServiceTest()
            Dim service As MySvc = New MySvcClient()
            Dim input As MyInput = New MySvcInput()
            input.A = testContextInstance.DataRow("A")
            input.B = testContextInstance.DataRow("B")
            Dim g As Guid = Guid.NewGuid()
            If TestContext.Properties.Contains("$LoadTestUserContext") Then 'running as load test
                TestContext.BeginTimer("MySvcTrans")
                Debug.WriteLine("Begin Transaction MySvcTrans:  {0}", g)
            End If
            Dim output As MySvcOutput = service.Method(input)
            If TestContext.Properties.Contains("$LoadTestUserContext") Then 'running as load test
                Debug.WriteLine("End Transaction MySvcTrans:  {0}", g)
                TestContext.EndTimer("MySvcTrans")
            End If
            Assert.AreEqual(0, output.ReturnCode)
        End Sub

    Hi John,
    >> I expect a Transaction to appear in the load test results for each row in my DataSource due to the BeginTimer and EndTimer methods in the unit test.  However, I only get 1 transaction, with response time roughly equal to the overall test
    time.
    Could you share me a screen shot about the reslut in load test?
    Could you share us the load test result in "Transaction"Tables?
    About how to use the
    Transaction for unit tests, maybe you could get useful informaiton here:
    http://blogs.msdn.com/b/slumley/archive/2006/04/14/load-testing-web-services-with-unit-tests.aspx
    Best Regards,
    Jack
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Support for unit testing object types

    There's a Feature Request that suggests expanding the unit test tool to object types:
    Title
    Provide object type support for unit tests
    Description
    In the current version (2.1.0.63) I can perform only unit test for packages, function and procedures. But we use a lot of object types in the database and would like to test them. When is a support for object types scheduled?
    Average Rating
    10
    Development Comment
    This is planned for the next release.
    Status
    Scheduled for 3.0
    Although the status suggests inclusion in v3, in my current version 3.2.20.09 there is nothing.
    This is clearly an important issue for those who have voted for it as it scores a perfect 10 on average rating.
    Is there any sign of object types being supported in the 4.0EA1 release? There is a strong desire within my organisation to move to a more object-based approach to PL/SQL coding but until we are able to unit test easily there will be no real progress.

    If you are ready to learn a little bit of Ruby then you can try [PL/SQL unit testing with Ruby|http://blog.rayapps.com/2009/11/27/oracle-plsql-unit-testing-with-ruby/]. ruby-plsql library [supports also PL/SQL object types|http://blog.rayapps.com/2009/11/25/more-oracle-data-types-supported-by-ruby-plsql-gem/] as input and output parameters and return values.

Maybe you are looking for