NetBeans Rich Client Platform Simpletests Anton Epple Eppleton IT - - PowerPoint PPT Presentation

netbeans rich client platform simpletests anton epple
SMART_READER_LITE
LIVE PREVIEW

NetBeans Rich Client Platform Simpletests Anton Epple Eppleton IT - - PowerPoint PPT Presentation

NetBeans Rich Client Platform Simpletests NetBeans Rich Client Platform Simpletests Anton Epple Eppleton IT Consulting NetBeans Rich Client Platform Unit tests for RCP Applications Introduced in 6.5 Before: Xtest infrastructure Unit &


slide-1
SLIDE 1

NetBeans Rich Client Platform

Simpletests

NetBeans Rich Client Platform Simpletests Anton Epple

Eppleton IT Consulting

slide-2
SLIDE 2

NetBeans Rich Client Platform

Unit tests for RCP Applications

Introduced in 6.5 Before: Xtest infrastructure

Unit & Functional Tests hard to set up for custom RCP projects

Modifications:

SimpleTest is based on Modules itself => Easy setup

slide-3
SLIDE 3

NetBeans Rich Client Platform

Unit tests for RCP Applications

JUnit 4 NetBeans Extensions to Junit (NBJUnit):

compare files via assertFile create working directories for testcases write to log files compare log files against reference (golden) files, etc.

Jemmy for functional Tests NetBeans Extensions for Jemmy: Jelly

slide-4
SLIDE 4

NetBeans Rich Client Platform

Unit tests for RCP Applications

Pattern for Dependency Injection with lookups:

abstract class DialogDisplayer { public abstract void notify(String msg); public static DialogDisplayer getDefault() { return Lookup.getDefault().lookup(DialogDisplayer.class); } }

In Test:

public class MyTest extends NbTestCase { public MyTest(String name) { super(name); } protected void setUp() throws Exception { super.setUp();

  • rg.netbeans.junit.MockServices.setServices(MockDD.class);

} }

slide-5
SLIDE 5

NetBeans Rich Client Platform

Unit tests for RCP Applications

Setting up more than one service:

public class MyTest extends NbTestCase { static { System.setProperty("org.openide.util.Lookup", Lkp.class.getName()); } public MyTest(String name) { super(name); } public static final class Lkp extends

  • rg.openide.util.lookup.AbstractLookup {

public Lkp() { this(new org.openide.util.lookup.InstanceContent()); } private Lkp(org.openide.util.lookup.InstanceContent ic) { super(ic); ic.add(new DD());

slide-6
SLIDE 6

NetBeans Rich Client Platform

Unit Test Dependencies

Unit Tests can have dependencies on other Modules:

slide-7
SLIDE 7

NetBeans Rich Client Platform

Unit Test Dependencies

...and their Test Classes (Demo NurEinTest):

slide-8
SLIDE 8

NetBeans Rich Client Platform

Unit Test Dependencies

Considerations for adding Test Mock & Helper classes to modules: API Design: Programming against Interfaces just for testing problematic in terms of API evolution

Can't add new methods in Interface without breaking compatibility

Alternatively: Testability part of the API

→ Testable binary modules (Platform Chaining)

slide-9
SLIDE 9

NetBeans Rich Client Platform

Unit Test in AWT Thread

NBTestCase supports running in AWT Dispatch Thread: public class MyTest extends NbTestCase { @override protected boolean runInEQ () { return true; } } More Tips: http://openide.netbeans.org/tutorial/test-patterns.html

slide-10
SLIDE 10

NetBeans Rich Client Platform

Functional UI Tests: Jelly

NetBeans supports Jemmy for automated ui testing:

https://jemmy.dev.java.net/ Independent of test harness

Jelly is a set of Extensions to Jemmy specifically to test NB Platform applications Jelly Tests are based on JUnit JellyTestCase extends NBTestCase Setup in project is simple but not straightforward...

slide-11
SLIDE 11

NetBeans Rich Client Platform

Functional UI Tests: Jelly

Required Modules: Cluster harness, MultiView Windows + Visual Library from platform9 In Modules test dir: folder qa-functional/src IDE restart adds 2 Nodes to Module:

Functional Test Packages Functional Test Libraries

Required Functional Test Libraries: jemmy, nbjunit, jellytools platform and junit4

slide-12
SLIDE 12

NetBeans Rich Client Platform

Functional UI Tests: Jelly

In project.xml (Project Metadata) add the recursive tag to the nbjunit dependency:

<test-dependency> <code-name-base>org.netbeans.modules.nbjunit</code-name-base> <compile-dependency/> <recursive/> </test-dependency>

slide-13
SLIDE 13

NetBeans Rich Client Platform

Functional Tests: JellyTestCase

public class SampleTest extends JellyTestCase { public SampleTest(String name) { super(name); } public static Test suite() { Configuration testConfig = NbModuleSuite.createConfiguration(SampleTest.class); testConfig.addTest("testSomething"); testConfig.clusters(".*").enableModules(".*"); testConfig.gui(true); return NbModuleSuite.create(testConfig); } public void setUp() { System.out.println("######## "+getName()+" #######"); } public void testSomething() { new Action("File|Some Action", null).perform(); } }

slide-14
SLIDE 14

NetBeans Rich Client Platform

Functional Testing

Demo

slide-15
SLIDE 15

NetBeans Rich Client Platform

Functional UI Tests

Considerations: Possible to run automated UI test with Jemmy Downside:

Not easy to write & maintain May cause false alarms (e.g. renamed Menu Items aren't necessarily Bugs)

Manual Testing with test scripts

slide-16
SLIDE 16

NetBeans Rich Client Platform

Practical Tips for Testing & CI

commit-validation Small Test suite runs before every commit (5 minutes) Large test suite runs on CI server Example: http://www.netbeans.org/community/guidelines/commit.html

slide-17
SLIDE 17

NetBeans Rich Client Platform

Functional UI Tests

Besides Testing: PMD ( PMD scans Java source code for Bugs, duplications, ... ) FindBugs ( static code analysis ) CheckStyle ( Enforce Coding Standards ) Lint4j ( find Locking & Threading Issues ) SQE (contains all 4) in a NB Plugin (sqe.kenai.org)

slide-18
SLIDE 18

NetBeans Rich Client Platform

Links & Resources

http://wiki.netbeans.org/DevFaqUsingSimpletests http://wiki.netbeans.org/FitnessTestsWithoutX http://wiki.netbeans.org/XTestReplacementCookBook

slide-19
SLIDE 19

NetBeans Rich Client Platform

Thank you!

Q & A