test_case_generator 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2fd026581bd0bc429eb04313a282515db6824cd
|
4
|
+
data.tar.gz: c6e958fa78801959f64789ca205f3d8d9f48a756
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 933be1201506bfba53a7ce57482cb216de6df96739125138095ee370e625e59a0ca90e09094c87595f754c7701debb2b0cf18d769d244b35849eeae2d4b39f38
|
7
|
+
data.tar.gz: ecb54cdc5bed936199a889d691e0a149335bbc18e4e1753da2f7423b8849e51404a8487f6e20529a864e6bdadd7a59319df8bb7863817165a97d4aa1176baeab
|
data/README.md
CHANGED
@@ -22,7 +22,41 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
Write a .testcase file.
|
26
|
+
|
27
|
+
Ex. Tests for a TableView in ViewController (YMTableView.testcase)
|
28
|
+
|
29
|
+
before { |items|
|
30
|
+
items << :prepareTarget
|
31
|
+
}
|
32
|
+
|
33
|
+
concat {
|
34
|
+
choice { |items|
|
35
|
+
items << :emptyList
|
36
|
+
items << :oneItemInList
|
37
|
+
items << :manyItemsInList
|
38
|
+
}
|
39
|
+
|
40
|
+
choice { |items|
|
41
|
+
items << [:viewDidLoad, :viewDidUnload]
|
42
|
+
items << [:viewDidLoad, :viewWillAppear, :viewDidAppear, :viewWillDisappear, :viewDidDisappear, :viewDidUnload]
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
after { |items|
|
47
|
+
items << :releaseTarget
|
48
|
+
}
|
49
|
+
|
50
|
+
To generate the .m file, run the test_case_generator. (YMTableView.m)
|
51
|
+
|
52
|
+
bundle exec test_case_generator inject YMTableView.testcase YMTableView.m
|
53
|
+
|
54
|
+
If the .testcase file is modified after generated, rerun the test_case_generator.
|
55
|
+
|
56
|
+
bundle exec test_case_generator inject YMTableView.testcase YMTableView.m
|
57
|
+
|
58
|
+
Do not delete %% marker in the generated .m file because the lines after %% marker is rewritten.
|
59
|
+
|
26
60
|
|
27
61
|
## Development
|
28
62
|
|
@@ -8,10 +8,77 @@ module TestCaseGenerator
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def write(ctx, source_fn)
|
11
|
-
|
11
|
+
write_skeleton source_fn unless File.exists? source_fn
|
12
|
+
write_interface ctx, File.join(File.dirname(source_fn), make_interface_name(source_fn)) + '.java'
|
12
13
|
write_source ctx, source_fn
|
13
14
|
end
|
14
15
|
|
16
|
+
|
17
|
+
def make_class_name(filename)
|
18
|
+
# File.join(File.dirname(source_fn), File.basename(source_fn, File.extname(source_fn))
|
19
|
+
File.basename filename, ".*"
|
20
|
+
end
|
21
|
+
|
22
|
+
def make_interface_name(filename)
|
23
|
+
make_class_name(filename) + 'Generated'
|
24
|
+
end
|
25
|
+
|
26
|
+
def make_package_name(filename)
|
27
|
+
parts = []
|
28
|
+
java_seen = false
|
29
|
+
File.absolute_path(File.dirname(filename)).split('/').each do |x|
|
30
|
+
if java_seen
|
31
|
+
parts << x
|
32
|
+
end
|
33
|
+
if x == 'java'
|
34
|
+
java_seen = true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
if parts.empty?
|
39
|
+
'com.example'
|
40
|
+
else
|
41
|
+
parts.join '.'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def write_skeleton(source_fn)
|
46
|
+
class_name = make_class_name(source_fn)
|
47
|
+
File.open(source_fn, 'w') do |f|
|
48
|
+
writer = IndentedWriter.new f
|
49
|
+
writer.puts <<EOS
|
50
|
+
package #{make_package_name source_fn};
|
51
|
+
|
52
|
+
import android.content.Context;
|
53
|
+
|
54
|
+
import org.junit.After;
|
55
|
+
import org.junit.Before;
|
56
|
+
import org.junit.Test;
|
57
|
+
import org.junit.runner.RunWith;
|
58
|
+
import org.robolectric.Robolectric;
|
59
|
+
import org.robolectric.RobolectricTestRunner;
|
60
|
+
import org.robolectric.annotation.Config;
|
61
|
+
|
62
|
+
import static org.junit.Assert.*;
|
63
|
+
|
64
|
+
@RunWith(RobolectricTestRunner.class)
|
65
|
+
@Config(emulateSdk = 18)
|
66
|
+
public class #{class_name} implements #{make_interface_name source_fn} {
|
67
|
+
|
68
|
+
@Before
|
69
|
+
public void setUp() {
|
70
|
+
}
|
71
|
+
|
72
|
+
@After
|
73
|
+
public void tearDown() {
|
74
|
+
}
|
75
|
+
|
76
|
+
// %%
|
77
|
+
}
|
78
|
+
EOS
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
15
82
|
def write_interface(dsl_context, header_fn)
|
16
83
|
interface_name = File.basename(header_fn, File.extname(header_fn))
|
17
84
|
tmp_fn = header_fn + '.tmp'
|
@@ -46,6 +113,15 @@ module TestCaseGenerator
|
|
46
113
|
end
|
47
114
|
|
48
115
|
writer = IndentedWriter.new f
|
116
|
+
writer.blank
|
117
|
+
writer.block_indent ' ' do
|
118
|
+
writer.puts '//'
|
119
|
+
writer.puts '// 以下の行は自動生成されているので直接編集しないでください。'
|
120
|
+
writer.puts '//'
|
121
|
+
writer.puts '// Generated by Test Case Generator'
|
122
|
+
writer.puts '// https://rubygems.org/gems/test_case_generator'
|
123
|
+
writer.puts '//'
|
124
|
+
end
|
49
125
|
|
50
126
|
dsl_context.each do |pattern|
|
51
127
|
method_name = pattern.join '_'
|
@@ -65,7 +141,7 @@ module TestCaseGenerator
|
|
65
141
|
end
|
66
142
|
|
67
143
|
writer.blank
|
68
|
-
writer.puts '
|
144
|
+
writer.puts '}'
|
69
145
|
end
|
70
146
|
|
71
147
|
FileUtils.move tmp_fn, source_fn
|
@@ -8,10 +8,48 @@ module TestCaseGenerator
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def write(ctx, source_fn)
|
11
|
+
write_skeleton source_fn unless File.exists? source_fn
|
11
12
|
write_header ctx, File.join(File.dirname(source_fn), File.basename(source_fn, File.extname(source_fn)) + 'Generated.h')
|
12
13
|
write_source ctx, source_fn
|
13
14
|
end
|
14
15
|
|
16
|
+
def make_class_name(filename)
|
17
|
+
File.basename filename, ".*"
|
18
|
+
end
|
19
|
+
|
20
|
+
def write_skeleton(source_fn)
|
21
|
+
class_name = make_class_name(source_fn)
|
22
|
+
File.open(source_fn, 'w') do |f|
|
23
|
+
writer = IndentedWriter.new f
|
24
|
+
writer.puts <<EOS
|
25
|
+
#import <UIKit/UIKit.h>
|
26
|
+
#import <XCTest/XCTest.h>
|
27
|
+
#import "#{class_name}Generated.h"
|
28
|
+
|
29
|
+
#pragma mark - #{class_name}
|
30
|
+
|
31
|
+
@interface #{class_name} : XCTestCase <#{class_name}Generated>
|
32
|
+
@end
|
33
|
+
|
34
|
+
@implementation #{class_name}
|
35
|
+
|
36
|
+
- (void)setUp {
|
37
|
+
[super setUp];
|
38
|
+
}
|
39
|
+
|
40
|
+
- (void)tearDown {
|
41
|
+
[super tearDown];
|
42
|
+
}
|
43
|
+
|
44
|
+
#pragma mark #{class_name}Generated
|
45
|
+
|
46
|
+
// TODO: ここにアクションを書いてください
|
47
|
+
|
48
|
+
// %%
|
49
|
+
EOS
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
15
53
|
def write_header(dsl_context, header_fn)
|
16
54
|
protocol_name = File.basename(header_fn, File.extname(header_fn))
|
17
55
|
tmp_fn = header_fn + '.tmp'
|
@@ -23,7 +61,7 @@ module TestCaseGenerator
|
|
23
61
|
writer.puts "@protocol #{protocol_name} <NSObject>"
|
24
62
|
|
25
63
|
dsl_context.labels.each do |label|
|
26
|
-
method_name = label
|
64
|
+
method_name = Utils.make_method_name label
|
27
65
|
writer.puts "- (void)#{method_name};"
|
28
66
|
end
|
29
67
|
|
@@ -43,6 +81,13 @@ module TestCaseGenerator
|
|
43
81
|
end
|
44
82
|
|
45
83
|
writer = IndentedWriter.new f
|
84
|
+
writer.blank
|
85
|
+
writer.puts '//'
|
86
|
+
writer.puts '// 以下の行は自動生成されているので直接編集しないでください。'
|
87
|
+
writer.puts '//'
|
88
|
+
writer.puts '// Generated by Test Case Generator'
|
89
|
+
writer.puts '// https://rubygems.org/gems/test_case_generator'
|
90
|
+
writer.puts '//'
|
46
91
|
|
47
92
|
dsl_context.each do |pattern|
|
48
93
|
method_name = pattern.join '_'
|
@@ -8,10 +8,40 @@ module TestCaseGenerator
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def write(ctx, source_fn)
|
11
|
+
write_skeleton source_fn unless File.exists? source_fn
|
11
12
|
write_source ctx, source_fn
|
12
13
|
end
|
13
14
|
|
15
|
+
def make_class_name(filename)
|
16
|
+
File.basename filename, ".*"
|
17
|
+
end
|
18
|
+
|
19
|
+
def write_skeleton(source_fn)
|
20
|
+
class_name = make_class_name(source_fn)
|
21
|
+
File.open(source_fn, 'w') do |f|
|
22
|
+
writer = IndentedWriter.new f
|
23
|
+
writer.puts <<EOS
|
24
|
+
#!/usr/bin/env python
|
25
|
+
# -*- coding: utf-8 -*-
|
26
|
+
import os
|
27
|
+
import sys
|
28
|
+
import unittest
|
29
|
+
|
30
|
+
|
31
|
+
class #{class_name}(unittest.TestCase):
|
32
|
+
def setUp(self):
|
33
|
+
super(#{class_name}, self).setUp()
|
34
|
+
|
35
|
+
def tearDown(self):
|
36
|
+
super(#{class_name}, self).tearDown()
|
37
|
+
|
38
|
+
# %%
|
39
|
+
EOS
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
14
43
|
def write_source(dsl_context, source_fn)
|
44
|
+
class_name = make_class_name(source_fn)
|
15
45
|
tmp_fn = source_fn + '.tmp'
|
16
46
|
source = File.open(source_fn).read
|
17
47
|
File.open(tmp_fn, 'w') do |f|
|
@@ -45,46 +75,33 @@ module TestCaseGenerator
|
|
45
75
|
end
|
46
76
|
end
|
47
77
|
|
78
|
+
method_list = dsl_context.labels.map { |m| "'#{m}'" }.join(', ')
|
48
79
|
writer.blank
|
49
|
-
writer.
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
writer.puts "' pass',"
|
63
|
-
writer.puts "'',"
|
64
|
-
end
|
65
|
-
writer.puts ']'
|
66
|
-
writer.puts 'sane = False'
|
67
|
-
end
|
68
|
-
end
|
80
|
+
writer.puts <<EOS
|
81
|
+
@classmethod
|
82
|
+
def checkSanity(cls):
|
83
|
+
sane = True
|
84
|
+
msg = []
|
85
|
+
for method in [#{method_list}]:
|
86
|
+
if not hasattr(cls, method):
|
87
|
+
msg += [
|
88
|
+
' def %s(self):' % method,
|
89
|
+
' pass',
|
90
|
+
'',
|
91
|
+
]
|
92
|
+
sane = False
|
69
93
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
writer.puts "print \"\\n\".join(msg)"
|
76
|
-
writer.puts 'raise SystemExit(1)'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
94
|
+
if not sane:
|
95
|
+
print cls.__name__ + ' must implement following method(s):'
|
96
|
+
print
|
97
|
+
print "\\n".join(msg)
|
98
|
+
raise SystemExit(1)
|
80
99
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
writer.puts 'unittest.main()'
|
87
|
-
end
|
100
|
+
|
101
|
+
if __name__ == '__main__':
|
102
|
+
#{class_name}.checkSanity()
|
103
|
+
unittest.main()
|
104
|
+
EOS
|
88
105
|
end
|
89
106
|
|
90
107
|
FileUtils.move tmp_fn, source_fn
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_case_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kaoru Yanase
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|